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: django@… 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)

django.contrib.admin.views.main.py.diff (415 bytes ) - added by Ben Ford <ben.fordnz@…> 18 years ago.
diff of the necessary changes to django.contrib.admin.views.main.py
main.diff (807 bytes ) - added by Sergey Kirillov <rushman@…> 18 years ago.
Updated patch

Download all attachments as: .zip

Change History (11)

comment:1 by ben.fordnz@…, 18 years ago

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
---

rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column

by Ben Ford <ben.fordnz@…>, 18 years ago

diff of the necessary changes to django.contrib.admin.views.main.py

comment:2 by Ben Ford <ben.fordnz@…>, 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 Sergey Kirillov <rushman@…>, 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.

by Sergey Kirillov <rushman@…>, 18 years ago

Attachment: main.diff added

Updated patch

comment:4 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: UnreviewedAccepted

It has been mentioned that this ticket might be fixed by #3002.

comment:5 by Gary Wilson, 17 years ago

Summary: [patch] Sorting on FK model with desc ordering breaks admin change_listSorting on ForeignKey field whose model uses desc ordering breaks admin change_list

comment:6 by Gary Wilson, 17 years ago

Note, this was fixed in newforms-admin branch in [5122].

comment:7 by James Bennett, 17 years ago

#6127 was a duplicate.

comment:8 by Ramiro Morales, 17 years ago

Keywords: nfa-fixed added

comment:9 by Brian Rosner, 16 years ago

Resolution: fixed
Status: newclosed

This is no longer a problem since the merge of newforms-admin in [7967].

Note: See TracTickets for help on using tickets.
Back to Top