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: 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@…> 16 years ago.
diff of the necessary changes to django.contrib.admin.views.main.py
main.diff (807 bytes) - added by Sergey Kirillov <rushman@…> 16 years ago.
Updated patch

Download all attachments as: .zip

Change History (11)

comment:1 Changed 16 years ago by ben.fordnz@…

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

Changed 16 years ago by Ben Ford <ben.fordnz@…>

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

comment:2 Changed 16 years ago by Ben Ford <ben.fordnz@…>

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 Sergey Kirillov <rushman@…>

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.

Changed 16 years ago by Sergey Kirillov <rushman@…>

Attachment: main.diff added

Updated patch

comment:4 Changed 16 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedAccepted

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

comment:5 Changed 16 years ago by Gary Wilson

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 Changed 16 years ago by Gary Wilson

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

comment:7 Changed 15 years ago by James Bennett

#6127 was a duplicate.

comment:8 Changed 15 years ago by Ramiro Morales

Keywords: nfa-fixed added

comment:9 Changed 15 years ago by Brian Rosner

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