Как показать все товары, если не применяется ни один фильтр
class ProductListView(TemplateView): template_name = "storefront/shop/product/list.html"
def get_context(self,request,id,slug, *args, **kwargs):
category = get_object_or_404(Category,id=id,slug=slug)
return category.get_option_list_context(request)
def get(self, request,id, slug, *args, **kwargs):
template=self.template_name
if request.GET.get('ajax'):
# print("In ajax call")
template = "storefront/shop/product/includes/sidebar.html"
if request.GET.get('pagination_ajax'):
template = "storefront/shop/product/includes/list-ajax.html"
return render(request, template, self.get_context(request,id, slug, args, kwargs))
Используйте ListView и переопределите метод get_queryset:
from django.views.generic import ListView
class ProductListView(ListView):
model = Product
template_name = "storefront/shop/product/list.html"
def get_queryset(self, **kwargs):
object_list = Product.objects.all()
if self.request.GET.get('some_filter'):
# filter here
return object_list