Opened 16 years ago
Closed 15 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 Changed 16 years ago by
Changed 16 years ago by
Attachment: | django.contrib.admin.views.main.py.diff added |
---|
diff of the necessary changes to django.contrib.admin.views.main.py
comment:2 Changed 16 years ago by
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 Changed 16 years ago by
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 Changed 16 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 Changed 16 years ago by
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 Changed 15 years ago by
Keywords: | nfa-fixed added |
---|
comment:9 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
This is no longer a problem since the merge of newforms-admin in [7967].
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
---