Opened 10 years ago

Closed 8 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: UI/UX:

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

Download all attachments as: .zip

Change History (11)

comment:1 Changed 10 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 10 years ago by Ben Ford <ben.fordnz@…>

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

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

  • Summary changed from Sorting on FK model with desc ordering breaks admin change_list to [patch] Sorting on FK model with desc ordering breaks admin change_list

comment:3 Changed 10 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 10 years ago by Sergey Kirillov <rushman@…>

Updated patch

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

  • Triage Stage changed from Unreviewed to Accepted

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

comment:5 Changed 9 years ago by gwilson

  • Summary changed from [patch] Sorting on FK model with desc ordering breaks admin change_list to Sorting on ForeignKey field whose model uses desc ordering breaks admin change_list

comment:6 Changed 9 years ago by gwilson

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

comment:7 Changed 9 years ago by ubernostrum

#6127 was a duplicate.

comment:8 Changed 8 years ago by ramiro

  • Keywords nfa-fixed added

comment:9 Changed 8 years ago by brosner

  • Resolution set to fixed
  • Status changed from new to closed

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