Django regroup not working as expected

前端 未结 1 429
难免孤独
难免孤独 2021-01-29 00:22

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         


        
1条回答
  •  感动是毒
    2021-01-29 00:38

    {% regroup salecur by sale_date as sale_list %}
    
    
      {% for sale_date in sale_list %}
    • {{ sale_date.grouper }}
        {% for sale in sale_date.list %}
      • {{ sale.item }} - {{ sale.qty }}
      • {% endfor %}
    • {% endfor %}

    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 with gender='Male').

    0 讨论(0)
提交回复
热议问题