I am trying to make some efficient queries with Django in the following loop:
for division in divisions:
playoffs = league.playoff_set.filter(division=division, double_elimination=True)
I thought maybe filtering playoffs
before the loop by selecting only those with double_elimination=True
would enhance it:
playoffs = league.playoff_set.filter(double_elimination=True)
for division in divisions:
division_playoffs = playoffs.filter(division=division)
But now I am concerned that this is firing the query from playoffs
in every run at the loop instead of filtering on the previously retrieved result.
Is it working as expected or as I am fearing? Should I use Q
instead to build these better-performing queries?