循环中的Django模板比较

时间:2012-10-26 19:06:10

标签: django templates comparison

我需要将模型的值与模板中聚合的结果进行比较。 像一个:

{% for valor in valores %}
    {{ valor.quantidade }}
{% endfor %}
results of my loop

{{ total.total_quantidade }}
this is the result of my Aggregate

我如何比较这些值?

我的{% for valor ... %}

的结果列表
1000
2000
3000

我的汇总结果

1500

{% if total.quantidade_total >= valor.quantidade %}显示等效值..依此类推,如果较小则显示另一个值

我该怎么办?

1 个答案:

答案 0 :(得分:3)

困难是什么?

{% for valor in valores %}
    {% if total.quantidade_total >= valor.quantidade %}
        Do something
    {% else %}
        Do something else
    {% endif %}
{% endfor %}
相关问题