[Django] #16979: adds Q objects for related fields.

11 views
Skip to first unread message

Django

unread,
Oct 3, 2011, 1:55:59 PM10/3/11
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
----------------------------------------------+----------------------------
Reporter: javier@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.3
Severity: Normal | Keywords: Q,
Triage Stage: Unreviewed | related_fields
Easy pickings: 0 | Has patch: 1
| UI/UX: 0
----------------------------------------------+----------------------------
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')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16979>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 3, 2011, 4:27:01 PM10/3/11
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
-------------------------------------+-------------------------------------
Reporter: javier@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: SVN
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Q, related_fields | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by carljm):

* needs_better_patch: => 0
* version: 1.3 => SVN
* needs_docs: => 1
* needs_tests: => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/16979#comment:1>

Django

unread,
Oct 4, 2011, 10:34:03 AM10/4/11
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
-------------------------------------+-------------------------------------
Reporter: javier@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: SVN
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Q, related_fields | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/16979#comment:2>

Django

unread,
May 31, 2013, 4:07:04 PM5/31/13
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
-------------------------------------+-------------------------------------

Reporter: javier@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master

(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Q, related_fields | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by timo):

https://github.com/django/django/pull/580

--
Ticket URL: <https://code.djangoproject.com/ticket/16979#comment:3>

Django

unread,
Feb 7, 2014, 1:49:44 PM2/7/14
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
-------------------------------------+-------------------------------------

Reporter: javier@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Q, related_fields | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1
* needs_tests: 1 => 0
* needs_docs: 1 => 0


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/16979#comment:4>

Django

unread,
Dec 31, 2021, 7:33:17 AM12/31/21
to django-...@googlegroups.com
#16979: adds Q objects for related fields.
-------------------------------------+-------------------------------------
Reporter: javier@… | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: Q, related_fields | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix
* stage: Accepted => Unreviewed


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/16979#comment:5>

Reply all
Reply to author
Forward
0 new messages