Opened 8 years ago

Closed 8 years ago

#5057 closed (duplicate)

Ordering by a foreign key which has a descending ordering fails

Reported by: Robert Myers <myer0052@…> Owned by: adrian
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If you have two models like this:

class MyYear(models.Model):
    year = models.PositiveIntegerField()

    class Meta:
        ordering = ('-year',)

class OtherYear(models.Model):
    year = models.ForeignKey(MyYear)
    other_field = models.CharField(maxlength=100)
    
    class Meta:
        ordering = ('year')
    
    class Admin:
        list_display = ('year', 'other_field')

The Admin page for the second model gives a 500 error something along the lines:

ERROR: column app_myyear.-year does not exist SELECT

It appears the get_query_set method in the ChangeList class just blindly combines the table_name and its _meta.ordering together giving you 'table.-field'

Attachments (1)

admin_ordering.diff (739 bytes) - added by Robert Myers <myer0052@…> 8 years ago.
related ordering patch for admin interface

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by Robert Myers <myer0052@…>

related ordering patch for admin interface

comment:1 Changed 8 years ago by gwilson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

duplicate of #2895.

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