Opened 18 years ago
Closed 16 years ago
#2895 closed defect (fixed)
Sorting on ForeignKey field whose model uses desc ordering breaks admin change_list
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | nfa-fixed |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
On line 709 of contrib.admin.views.main.ChangeList
, the lookup assumes that f.rel.to._meta.ordering[0]
will return a valid column name. Not so in the case of '-fieldname'.
Attachments (2)
Change History (11)
comment:1 by , 18 years ago
by , 18 years ago
Attachment: | django.contrib.admin.views.main.py.diff added |
---|
diff of the necessary changes to django.contrib.admin.views.main.py
comment:2 by , 18 years ago
Summary: | Sorting on FK model with desc ordering breaks admin change_list → [patch] Sorting on FK model with desc ordering breaks admin change_list |
---|
comment:3 by , 18 years ago
Patch from this ticket breaks ability to change sorting of rows by clicking on column header. With this patch clicking on column header has no effect.
comment:4 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 17 years ago
Summary: | [patch] Sorting on FK model with desc ordering breaks admin change_list → Sorting on ForeignKey field whose model uses desc ordering breaks admin change_list |
---|
comment:8 by , 17 years ago
Keywords: | nfa-fixed added |
---|
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This is no longer a problem since the merge of newforms-admin in [7967].
Note:
See TracTickets
for help on using tickets.
Here's a quick hack that solves this problem for me. It's not tested, but it seems to work in my case.
709,713c709
< o_field = f.rel.to._meta.ordering[0]
< if o_field[0] == '-':
< self.order_type = 'desc'
< o_field = o_field[1:]
< rel_ordering = f.rel.to._meta.ordering and o_field or f.rel.to._meta.pk.column
---