Opened 18 years ago
Closed 18 years ago
#5057 closed (duplicate)
Ordering by a foreign key which has a descending ordering fails
| Reported by: | 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)
Note:
See TracTickets
for help on using tickets.
related ordering patch for admin interface