Clean up the code for a lot of our centralized query logic.
Review Request #12339 — Created June 3, 2022 and submitted
This is a basic cleanup change that improves the readability of several
of the larger query-building functions in our model managers. This
mainly centers around:
Consistent naming (
q
vs.queryset
instead ofquery
being used
for either orqs
sometimes being used).
|=
and&=
instead ofq = q |
orq = q &
.Doing as much with
Q()
objects as possible before calling methods
likefilter(...)
.Starting with a
Q()
object before any conditional logic, instead of
starting fresh inside of conditionals, to avoid potential issues with
logic being overridden unintentionally.General formatting improvements to help readability of some logic
when combiningQ()
objects.Using our modern chaining-like formatting for multi-line queryset
conditionals (chainingfilter()
andorder_by()
across lines, for
instance).This helps ensure more consistent code going forward, and lays a
foundation for some query optimization work that is coming.
All unit tests pass.
- Change Summary:
-
Added a missing unstaged line.
- Commits:
-
Summary ID 267347a48d77308e92cc0893dffe1696b20a8262 46fc50c76f7e5c38380e9ef68036b049cb167284