0
モデルCoperと、価格の引用符を動的に取得する必要があるかどうかを選択するフィールドがあります。したがって、ユーザーが「動的」を選択すると、ユーザーは製品および他の料金の見積もりを取得します。TemplateTagを使用した計算の処理なし
私は商品IDを取得し、売り手の通貨をフィルターに掛け、別のモデルのレートを検索して見積もりを完成させるテンプレートタグを書いた。
{% load quote_filter %}
{% for m in all_quotes %}
{% if m.pricing == 'dynamic' %}
{{m.id|get_total_quote }}
{% else %}
<p> Fixed price is $3500 </p>
{% endif %}
{% empty %}
<p> No product yet. </p>
{% endfor %}
私はサイトをロード
@register.filter(name='get_total_quote')
def get_total_quote(value):
tap = Coper.objects.get(pk=value)
get_cnd = VAM.objects.get(money_code = tap.seller.profile.currency)
ratex = get_cnd.money_rate
if tap.margin_type == 'plus':
percent = tap.margin_figure/100
addup = ratex * percent
total_amt = ratex + addup
return total_amt
if tap.margin_type == 'minus':
percent = tap.margin_figure/100
addup = ratex * percent
total_namt = ratex - addup
return total_namt
テンプレートは、私は、ダイナミックな引用符の代わりに、実際の数字の価格としてNONEを得ませんでした。
私には何が欠けていますか?
追加いくつかの印刷やテンプレートタグへのロギング。 'margin_type'が' 'plus''でも' 'minus''でもない場合、テンプレートタグは' None'を返します。 – Alasdair
また、なぜIDだけをタグに渡してから、Coperに問い合わせるのですか? 「m」はすでにCoperオブジェクトではないのですか? –
@Alasdairはいそうです。どのように私はこれを逃したのか分からない!今すぐうまくいく!ありがとう。あなたをマークアップする答えとして投稿してください。 – YoYo