Opened 4 years ago

Last modified 20 months ago

#16979 new New feature

adds Q objects for related fields.

Reported by: javier@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: Q, related_fields
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Inspired by this proposal by Johannes Dollinger:!topic/django-developers/lH5UhciGTBw, this quick (untested!) patch allows to use

is_blue = Q(color='blue')

as a better alternative to:


being better because it generates the same query as:


Attachments (2)

df1.diff (1.7 KB) - added by javier@… 4 years ago.
df1.2.diff (2.2 KB) - added by javier@… 4 years ago.
improved, now it accepts Q(relfield=Q(...))

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by javier@…

comment:1 Changed 4 years ago by carljm

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.3 to SVN

Changed 4 years ago by javier@…

improved, now it accepts Q(relfield=Q(...))

comment:2 Changed 4 years ago by anonymous

cleaned up, now there's a tree.Node._prefix() instance method, and the Q.__init__() constructor does the (..., relfield=qobj, ...) => (..., qobj._prefix(relfield+'__'), ...) transformation. No need to modify the db.query code.

comment:4 Changed 20 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set

The patch needs to be updated to apply cleanly to trunk and also needs a mention in the release notes. Since the PR has been polluted with some unrelated commits, here's the commit for this feature:

Note: See TracTickets for help on using tickets.
Back to Top