Add support for prefixing query expressions
Review Request #7774 — Created Nov. 17, 2015 and submitted — Latest diff uploaded
A new utility method,
prefix_q
, has been added to facilitate
prefixing of query expressions. Query expressions, or (Q()
expressions) are Django's way of building theWHERE
(and related)
clauses when querying for models.If a foreign key
fk
exists from a modelA
toB
(that is,A.fk
points at an instance ofB
), then a query expression that is used
to filter instances ofB
can be used withA
via prefix_q:q_a = prefix_q('fk', q_b)
This allows complex queries that select one model to be reused to
select related models very easily.
Ran unit tests.