I have the following view in my django application
def ViewSale( request ):
salecur = Sale.objects.filter(user=2).order_by(\'sale_date\')
return render_t
{% regroup salecur by sale_date as sale_list %}
<ul>
{% for sale_date in sale_list %}
<li>{{ sale_date.grouper }}
<ul>
{% for sale in sale_date.list %}
<li>{{ sale.item }} - {{ sale.qty }} </li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
See the documentation on regroup:
{% regroup %}
produces a list of group objects. Each group object has two attributes:
grouper
-- the item that was grouped by (e.g., the string "Male" or "Female").
list
-- a list of all items in this group (e.g., a list of all people withgender='Male'
).