Reputation: 19
i want to filter out the of promotion count, and save the service_type and promotion code for that particular count
here is my view
promotions=Promotions.objects.filter(member=request.user)
dictt={}
for promotion in promotions:
c=customer_request.objects.filter(promotion=promotion)
e=c.count()
dictt[e]=e
for w in c:
coupon_code=Promotions.objects.get(pk=w.promotion_id)
dictt.update({e:{coupon_code.coupon_code,w.service_type}})
sorted_dictt = sorted(dictt.items(), key=operator.itemgetter(0), reverse=True)
and i am displaying dict on html as follows
{% for a in sorted_dictt %}
<tr>
<td style="color:#f38619;"></td>
<td style="color:#f38619;">{{a.1}}</td>
<td style="color:#f38619;">{{a.0}}</td>
</tr>
{%endfor%}
now i am getting result as:
it should be display as
how to do it?
Upvotes: 0
Views: 46
Reputation: 10598
The following line looks wrong:
# Here, dictt[e] is a set that contains coupon_code.coupon_code and w.service_type
dictt.update({e:{coupon_code.coupon_code,w.service_type}})
Instead, write:
dictt.update({e: coupon_code.coupon_code})
Upvotes: 1
Reputation: 1641
You should use dictionary like this:
{% for key, value in dict.items %}
{{key}}-{{value}}
{% endfor %}
Upvotes: 0