Does order
of filter
matter when you query in django?
MyModel.objects.filter(exp1).filter(exp2)
vs
MyModel.objects.filter(exp2).filter(exp1)
Are they same?
If you are just doing two simple filter
operations, then you're correct that order doesn't matter, but be careful. There are examples of when the order of your queryset methods do matter:
Rather than thinking of filter
as being fundamentally commutative, you're probably safer thinking of each queryset methods as being generally iterative upon the whatever preceded them. Multiple filters are not always simple SQL AND's. Take this for example (although it's still commutative in this case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With