I don't know if there's a quick way to do this, but what I want to do is a search according to six parameters, where 5 of them come from Select Inputs, and the other one from an Input text, the search needs to be more specific when more options are selected.
Is there a way to do this with lookups? Or I need to make an if
for every combination of parameters? If I have to write all the if's, what is the more efficient way? Because if I'll have to do 2^6
if
statements to cover all the combinations, that will be a little bit slow. Consider that the parameters doesn't have an specific order, so any combination is possible.
I was thinking in Q objects
but I don't know if they work for that, I have only used them for OR satements, I know that they can be used for and
statements too, but I don't know if they are different than using comma
. Probably something like this:
result = Product.objects.filter(Q(field1=param1)&Q(field2=param2)&Q(field3=param3)&Q(field4=param4)&Q(field5=param5)&Q(field6=param6))