Opened 4 years ago

Last modified 4 months ago

#19842 new Cleanup/optimization

annotate()-based solution to distinct and order_by problem

Reported by: jogwen Owned by:
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: avani9330 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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

Attachments (3)

add_annotate_suggestion.patch (1.1 KB) - added by Jef Geskens 4 years ago.
add_annotate_suggestion.2.patch (2.0 KB) - added by Jef Geskens 4 years ago.
annotate_values_solution.patch (2.3 KB) - added by avani9330@… 3 years ago.
Patch

Download all attachments as: .zip

Change History (24)

comment:1 Changed 4 years ago by dfanders

Needs documentation: set
Owner: changed from nobody to anonymous
Status: newassigned

comment:2 Changed 4 years ago by dfanders

Owner: changed from anonymous to dfanders

comment:3 Changed 4 years ago by Carl Meyer

Triage Stage: UnreviewedAccepted

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.

comment:4 Changed 4 years ago by Jef Geskens

Owner: changed from dfanders to anonymous

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

comment:5 Changed 4 years ago by Jef Geskens

Owner: changed from anonymous to Jef Geskens

Changed 4 years ago by Jef Geskens

comment:6 Changed 4 years ago by Jef Geskens

Has patch: set

comment:7 Changed 4 years ago by jonathanslenders

This documentation patch looks fine.

comment:9 Changed 4 years ago by jonathanslenders

Triage Stage: AcceptedReady for checkin

comment:10 Changed 4 years ago by Jef Geskens

Triage Stage: Ready for checkinAccepted

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

comment:11 Changed 4 years ago by Jef Geskens

Fixed a typo in the patch.

Changed 4 years ago by Jef Geskens

comment:12 Changed 4 years ago by Tim Graham

Patch needs improvement: set

comment:13 Changed 3 years ago by Tim Graham

Easy pickings: unset
Owner: Jef Geskens deleted
Status: assignednew

Changed 3 years ago by avani9330@…

Patch

comment:14 Changed 3 years ago by avani9330@…

Triage Stage: AcceptedReady for checkin

comment:15 in reply to:  14 Changed 3 years ago by avani9330

Cc: avani9330 added
Owner: set to avani9330
Status: newassigned

comment:16 Changed 3 years ago by avani9330

Patch needs improvement: unset

comment:17 Changed 3 years ago by avani9330

Needs documentation: unset

comment:18 Changed 3 years ago by avani9330

Triage Stage: Ready for checkinAccepted

comment:20 Changed 3 years ago by Marc Tamlyn

Patch needs improvement: set

comment:21 Changed 4 months ago by Tim Graham

Owner: avani9330 deleted
Status: assignednew
Version: 1.4master
Note: See TracTickets for help on using tickets.
Back to Top