Clean up the code for a lot of our centralized query logic.
Review Request #12339 — Created June 3, 2022 and submitted — Latest diff uploaded
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.