Opened 12 years ago

Last modified 8 years ago

#19842 new Cleanup/optimization

annotate()-based solution to distinct and order_by problem

Reported by: jogwen Owned by:
Component: Documentation Version: dev
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 11 years ago.
add_annotate_suggestion.2.patch (2.0 KB ) - added by Jef Geskens 11 years ago.
annotate_values_solution.patch (2.3 KB ) - added by avani9330@… 11 years ago.
Patch

Download all attachments as: .zip

Change History (24)

comment:1 by dfanders, 12 years ago

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

comment:2 by dfanders, 12 years ago

Owner: changed from anonymous to dfanders

comment:3 by Carl Meyer, 12 years ago

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 by Jef Geskens, 11 years ago

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 by Jef Geskens, 11 years ago

Owner: changed from anonymous to Jef Geskens

by Jef Geskens, 11 years ago

comment:6 by Jef Geskens, 11 years ago

Has patch: set

comment:7 by jonathanslenders, 11 years ago

This documentation patch looks fine.

comment:9 by jonathanslenders, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:10 by Jef Geskens, 11 years ago

Triage Stage: Ready for checkinAccepted

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

comment:11 by Jef Geskens, 11 years ago

Fixed a typo in the patch.

by Jef Geskens, 11 years ago

comment:12 by Tim Graham, 11 years ago

Patch needs improvement: set

comment:13 by Tim Graham, 11 years ago

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

by avani9330@…, 11 years ago

Patch

comment:14 by avani9330@…, 11 years ago

Triage Stage: AcceptedReady for checkin

in reply to:  14 comment:15 by avani9330, 11 years ago

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

comment:16 by avani9330, 11 years ago

Patch needs improvement: unset

comment:17 by avani9330, 11 years ago

Needs documentation: unset

comment:18 by avani9330, 11 years ago

Triage Stage: Ready for checkinAccepted

comment:20 by Marc Tamlyn, 11 years ago

Patch needs improvement: set

comment:21 by Tim Graham, 8 years ago

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