Opened 13 years ago
Last modified 9 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
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)
Change History (24)
comment:1 by , 13 years ago
| Needs documentation: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|
comment:3 by , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 13 years ago
| Owner: | changed from to |
|---|
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 , 13 years ago
| Owner: | changed from to |
|---|
by , 13 years ago
| Attachment: | add_annotate_suggestion.patch added |
|---|
comment:6 by , 13 years ago
| Has patch: | set |
|---|
comment:9 by , 13 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:10 by , 13 years ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
The documentation should be improved with an example, as suggested by @timgraham
by , 13 years ago
| Attachment: | add_annotate_suggestion.2.patch added |
|---|
comment:12 by , 12 years ago
| Patch needs improvement: | set |
|---|
comment:13 by , 12 years ago
| Easy pickings: | unset |
|---|---|
| Owner: | removed |
| Status: | assigned → new |
follow-up: 15 comment:14 by , 12 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:15 by , 12 years ago
| Cc: | added |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
comment:16 by , 12 years ago
| Patch needs improvement: | unset |
|---|
comment:17 by , 12 years ago
| Needs documentation: | unset |
|---|
comment:18 by , 12 years ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
comment:20 by , 12 years ago
| Patch needs improvement: | set |
|---|
comment:21 by , 9 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
| Version: | 1.4 → master |
Note:
See TracTickets
for help on using tickets.
I think it's probably true that many cases of people trying to use
distinctandorder_byon related fields together would be solved byannotate. It wouldn't hurt to mentionannotatein that note.