Whats wrong with my search string? I am not getting proper data

I want to implement search on my django project. On my following queryset, with else condition its passing correct data. But with if condition whatever I search, it shows nothing.

def get_queryset(self):
 category = self.request.GET['category']
 query = self.request.GET['q']
 if category == 'all':
            products = Products.objects.filter(Q(name__icontains=query) | Q(category__name__icontains=query)).all() 
             products = Products.objects.filter(Q(category__slug=category),  Q(category__slug__icontains=self.request.GET['q']) |  Q(name__icontains=self.request.GET['q']))

User will choose all or category name.

Could you please let me know where I am wrong here?

What specifically are the values of category and query being supplied in your test?

What does your Products model look like? (And any related models)