Answer the question
In order to leave comments, you need to log in
Filter problems?
Good afternoon! I'm trying to implement filters, but for some reason it doesn't work. In the view file, I have a class for displaying products:
class CategoryView(ListView):
template_name = '__index.html'
context_object_name = 'products'
paginate_by = 20
def get_queryset(self):
queryset = Product.objects.filter(category__slug=self.kwargs.get('slug')).order_by('-created')
request = self.request
# Filter By Brand and Country
if request.GET.get('country'):
print(request.GET.get('country'))
queryset.filter(brand__country__slug=request.GET.get('country'))
if request.GET.get('brand'):
print(request.GET.get('brand'))
queryset.filter(brand__slug=request.GET.get('brand'))
print(queryset[0].brand.slug)
print(queryset[0].brand.country.slug)
return queryset
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question