only show public categories

This commit is contained in:
Thomas Steen Rasmussen 2016-05-17 21:10:01 +02:00
parent 2303b175a0
commit 900bce6bc3

View file

@ -90,6 +90,8 @@ class ShopIndexView(ListView):
if 'category' in self.request.GET: if 'category' in self.request.GET:
category = self.request.GET.get('category') category = self.request.GET.get('category')
if not category.public:
raise Http404("Category not found")
context['products'] = context['products'].filter( context['products'] = context['products'].filter(
category__slug=category, category__slug=category,
public=True, public=True,
@ -98,7 +100,8 @@ class ShopIndexView(ListView):
context['categories'] = ProductCategory.objects.annotate( context['categories'] = ProductCategory.objects.annotate(
num_products=Count('products') num_products=Count('products')
).filter( ).filter(
num_products__gt=0 num_products__gt=0,
public=True,
) )
return context return context