diff --git a/shop/templates/shop_index.html b/shop/templates/shop_index.html index a7bf01cc..45df7340 100644 --- a/shop/templates/shop_index.html +++ b/shop/templates/shop_index.html @@ -27,22 +27,30 @@ Product - Category Price {% for product in products %} + + {% ifchanged product.category %} + + + + {{ product.category }} + + + + + {% endifchanged %} + {{ product.name }} - - {{ product.category }} -
{{ product.price|currency }} diff --git a/shop/views.py b/shop/views.py index d6c1e6ab..08cc0f03 100644 --- a/shop/views.py +++ b/shop/views.py @@ -141,6 +141,10 @@ class ShopIndexView(ListView): template_name = "shop_index.html" context_object_name = 'products' + def get_queryset(self): + queryset = super(ShopIndexView, self).get_queryset() + return queryset.order_by('category__name', 'price') + def get_context_data(self, **kwargs): context = super(ShopIndexView, self).get_context_data(**kwargs)