【发布时间】:2021-04-21 15:20:37
【问题描述】:
我想根据 django 模板中的条件计算对象总数。假设我的模型如下:
class Vote(models.Model):
election = models.ForeignKey(Election, on_delete=models.CASCADE)
candidate = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
voting_booth = models.ForeignKey(Booth, on_delete=models.CASCADE)
这里我想要基于每个投票展位的总票数。我可以在视图中对其进行过滤,但希望在其各自的展位上显示所有投票。
模板是:
{% for v in vote %}
<div class="col-md-6 col-sm-6 col-lg-6 col-xl-4">
<div class="dash-widget" style="box-shadow: 5px 5px lightblue;">
<div class="dash-widget-info">
<h5>Total Voters:{{v.**???**.count}}</h5>
<h5>Voting Booth:{{v.voting_booth}}</h5>
<h5>Total Vote Earned:{{v.**???**.count}}</h5>
</div>
</div>
</div>
{% endfor %}
提前致谢..
【问题讨论】: