What is the difference between filter with multiple arguments and chain filter in django?
The performance difference is huge. Try it and see.
Model.objects.filter(condition_a).filter(condition_b).filter(condition_c)
is surprisingly slow compared to
Model.objects.filter(condition_a, condition_b, condition_c)
As mentioned in Effective Django ORM,
- QuerySets maintain state in memory
- Chaining triggers cloning, duplicating that state
- Unfortunately, QuerySets maintain a lot of state
- If possible, don’t chain more than one filter