0
使用Django,我試圖輸出每個社區中的總數。使用Django標記獲取每個對象內的對象總數
社區有幾個地段,還有幾個社區。這裏是我得到的一個例子:
Total lots: 99.
該社區只有2個地段。他們之間共有4個社區,共9個社區。
模型和意見似乎是正確的。是否有一個我缺少的過濾器或寫這個來獲得正確結果的不同方式?
{% if community.is_active %}
<a class="panel-link" href="{% url 'community-detail' pk=community.id %}" %}>
<div class="col-md-6 community_col">
<div class="community_box">
<div class="row">
<br>
<div class="col-md-4 community_img">
<img src="/media/{{ community.logo }}" alt="">
</div>
<div class="col-md-7 col-md-offset-1">
<h1 style="margin-bottom: -10px; margin-top: -15px;"><small>{{ community.name }}</small></h1>
<h4>{{ community.city }}, {{ community.state }}</h4>
<h6>Total lots: {% for lot in community.lot_set.all %}{{ lots|length }}{% endfor %}</h6>
<h6>Total Active lots: </h6>
<h6>Total Sold lots: </h6>
<h6>Total Inactive lots: </h6>
</div>
</div>
</div>
</div>
</a>
{% endif %}
{% endfor %}
非常感謝。這確實有把戲。現在按照您的說法前進,通過註釋查詢集來完成數據庫中其餘的計數似乎是合理的。你可以擴展我將如何做到這一點?在模型或視圖? –