[Django] #19842: annotate()-based solution to distinct and order_by problem

13 views
Skip to first unread message

Django

unread,
Feb 18, 2013, 11:19:46 AM2/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+--------------------
Reporter: jogwen | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+--------------------
https://docs.djangoproject.com/en/1.4/ref/models/querysets/#django.db.models.query.QuerySet.distinct

Note about how distinct may not work when ordering by related model fields
could point the reader at this solution
http://archlinux.me/dusty/2010/12/07/django-dont-use-distinct-and-
order_by-across-relations/, using annotate().

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

Django

unread,
Feb 20, 2013, 9:37:23 PM2/20/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: anonymous
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dfanders):

* status: new => assigned
* needs_docs: => 1
* owner: nobody => anonymous
* needs_tests: => 0
* needs_better_patch: => 0


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

Django

unread,
Feb 20, 2013, 9:40:09 PM2/20/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: dfanders

Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dfanders):

* owner: anonymous => dfanders


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

Django

unread,
Feb 22, 2013, 1:04:31 PM2/22/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: dfanders
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by carljm):

* stage: Unreviewed => Accepted


Comment:

I think it's probably true that many cases of people trying to use
`distinct` and `order_by` on related fields together would be solved by
`annotate`. It wouldn't hurt to mention `annotate` in that note.

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

Django

unread,
May 18, 2013, 5:51:03 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: anonymous
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 1
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by jgeskens):

* owner: dfanders => anonymous


Comment:

I also came accross this problem. I will try to put this suggestion in the
Documentation as part of the DjangoCon Euro 2013 sprints.

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

Django

unread,
May 18, 2013, 5:53:40 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by jgeskens):

* owner: anonymous => jgeskens


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

Django

unread,
May 18, 2013, 6:47:56 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by jgeskens):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:6>

Django

unread,
May 18, 2013, 9:25:30 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by jonathanslenders):

This documentation patch looks fine.

--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:7>

Django

unread,
May 18, 2013, 9:51:14 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by jgeskens):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:8>

Django

unread,
May 18, 2013, 10:03:39 AM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: jgeskens

Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin

Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jonathanslenders):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:9>

Django

unread,
May 18, 2013, 12:13:06 PM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by jgeskens):

* stage: Ready for checkin => Accepted


Comment:

The documentation should be improved with an example, as suggested by
@timgraham

--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:10>

Django

unread,
May 18, 2013, 12:15:14 PM5/18/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by jgeskens):

Fixed a typo in the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:11>

Django

unread,
May 19, 2013, 11:46:42 AM5/19/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner: jgeskens
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:12>

Django

unread,
Sep 20, 2013, 1:55:45 PM9/20/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner:

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* owner: jgeskens =>
* status: assigned => new
* easy: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:13>

Django

unread,
Nov 2, 2013, 6:21:32 AM11/2/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner:
Type: | Status: new

Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by avani9330@…):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:14>

Django

unread,
Nov 2, 2013, 6:29:59 AM11/2/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned

Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by avani9330):

* status: new => assigned

* cc: avani9330 (added)
* owner: => avani9330


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:15>

Django

unread,
Nov 2, 2013, 9:22:45 AM11/2/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by avani9330):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:16>

Django

unread,
Nov 2, 2013, 9:23:18 AM11/2/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by avani9330):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:17>

Django

unread,
Nov 2, 2013, 9:25:52 AM11/2/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by avani9330):

* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:18>

Django

unread,
Nov 5, 2013, 4:08:35 PM11/5/13
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by bithin):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:19>

Django

unread,
Feb 9, 2014, 9:21:59 AM2/9/14
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
-------------------------------------+-------------------------------------
Reporter: jogwen | Owner: avani9330
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by mjtamlyn):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:20>

Django

unread,
Aug 19, 2016, 10:17:26 AM8/19/16
to django-...@googlegroups.com
#19842: annotate()-based solution to distinct and order_by problem
--------------------------------------+------------------------------------
Reporter: jogwen | Owner:
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* owner: avani9330 =>


* status: assigned => new

* version: 1.4 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/19842#comment:21>

Reply all
Reply to author
Forward
0 new messages