How can I do this?
I only what to filter if the request is set.
ex. if gender not set, the filter will be:
Test.objects.filter(categories=category, brands=brand)
def index(request):
gender = request.GET.get('gender')
category = request.GET.get('category')
brand = request.GET.get('brand')
Test.objects.filter(genders=gender, categories=category, brands=brand)
If you realize that filter conditions can be passed in as keyword arguments the solution becomes easier to visualize. For e.g. consider the snippet below. This is a verbose way of doing it:
Of course another way of doing this would be to use a form rather than pick up the values directly from the GET request.