Opened 13 years ago
Closed 3 years ago
#16979 closed New feature (wontfix)
adds Q objects for related fields.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | Q, related_fields |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Inspired by this proposal by Johannes Dollinger: https://groups.google.com/forum/?hl=en#!topic/django-developers/lH5UhciGTBw, this quick (untested!) patch allows to use
is_blue = Q(color='blue') Owner.objects.filter(thing=is_blue)
as a better alternative to:
Owner.objects.filter(thing__in=Thing.objects.filter(is_blue))
being better because it generates the same query as:
Owner.objects.filter(thing__color='blue')
Attachments (2)
Change History (7)
by , 13 years ago
comment:1 by , 13 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.3 → SVN |
by , 13 years ago
Attachment: | df1.2.diff added |
---|
comment:2 by , 13 years ago
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 by , 11 years ago
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:
https://github.com/emulbreh/django/commit/34223e1bc864dd4f776b1094f388bf2fdbddfbd5
comment:5 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Triage Stage: | Accepted → Unreviewed |
Thanks for this ticket, however the proposed API (.filter(thing=Q(color='blue'))
) is very confusing for me and I don't see any advantages over the existing API (.filter(thing__color='blue')
). Please start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, I'd like to reach a consensus before moving this forward.
improved, now it accepts Q(relfield=Q(...))