Opened 17 years ago

Closed 17 years ago

#5057 closed (duplicate)

Ordering by a foreign key which has a descending ordering fails

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

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@…> 17 years ago.
related ordering patch for admin interface

Download all attachments as: .zip

Change History (2)

by Robert Myers <myer0052@…>, 17 years ago

Attachment: admin_ordering.diff added

related ordering patch for admin interface

comment:1 by Gary Wilson, 17 years ago

Resolution: duplicate
Status: newclosed

duplicate of #2895.

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