From 029ec74389b6cf6ef5a069190f2fc98e266067fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 25 Aug 2016 12:04:47 +0200 Subject: [PATCH] Don't show non-active products. Also don't show categories which doesn't have any active products. --- shop/templates/shop_index.html | 8 +++++++- shop/views.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/shop/templates/shop_index.html b/shop/templates/shop_index.html index fc0c8ad7..1a3fb9fa 100644 --- a/shop/templates/shop_index.html +++ b/shop/templates/shop_index.html @@ -49,7 +49,7 @@ Shop | {{ block.super }} {% endifchanged %} - + {{ product.name }} @@ -61,6 +61,12 @@ Shop | {{ block.super }} + {% empty %} + + + Sorry no products found. + + {% endfor %} diff --git a/shop/views.py b/shop/views.py index 35f089cb..a6fe061a 100644 --- a/shop/views.py +++ b/shop/views.py @@ -171,7 +171,7 @@ class ShopIndexView(ListView): def get_queryset(self): queryset = super(ShopIndexView, self).get_queryset() - return queryset.order_by('category__name', 'price', 'name') + return queryset.available().order_by('category__name', 'price', 'name') def get_context_data(self, **kwargs): context = super(ShopIndexView, self).get_context_data(**kwargs) @@ -197,6 +197,7 @@ class ShopIndexView(ListView): ).filter( num_products__gt=0, public=True, + products__available_in__contains=timezone.now() ) return context