【发布时间】:2021-03-11 00:01:37
【问题描述】:
我有 3 个模型,即 Uses、Customer 和 Services。我有一个查询,其结果存储在变量 count 中。
这是查询
counts = Services.objects.filter(uses__customer=customer).annotate(times_used=Count('uses'))
每个 count[x].times_used 都有一个变量,x 范围从 0 到无穷大。
我在我的 html 中使用了一个 for 循环来获取我在视图中通过上下文传递的所有服务。 现在我需要为每个服务获取唯一的计数值。我该怎么做。
这是我的html代码
<table class='table table-bordered' id='dataTable' width='100%' cellspacing='0'>
<thead class='bg-primary'>
<tr class='text-white'>
<th>Service-Id</th>
<th>Service-name</th>
<th>Count</th>
<th>Price</th>
</tr>
</thead>
<tbody class="text-dark">
<tr>{% for service in services %}
<td>{{ service.id }}</td>
<td>{{ service.service_name }}</td>
<td>#code for printing count[x],times_used#</td>
<td>{{ service.price }}</td>
</tr>{% endfor %}
</tbody>
</table>
【问题讨论】:
-
您想获取给定服务的索引吗?或者通过相对于服务的索引显示具有相应信息的另一个列表?
-
我想显示另一个列表,其中包含与服务相关的索引的相应信息。
标签: python django django-templates