Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#469 closed defect (fixed)

Admin changelist assumes ForeignKey related object has ordering set

Reported by: oliver.andrich@… Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

Here follows a small part of the model I use in conjunction with a mysql database. I haven't switched anything, so my tables are created as MyISAM tables. (Sadly, I also need them to be MyISAMs.) As the foreign key "emulation" of Django works fine for my application so far, I just think I can stick to it even if that sounds like horror to real database guys. :)

But my problem is, when I hit the order "button" in the admin interface list view of the agencies table, I get the following Python stack trace. Do be more precise, this only happens when I try toorder the list using a field, that I referenced by a ForeignKey. Is this a bug or what I am doing wrong?

There's been an error:

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 64, in get_response
    response = callback(request, **param_dict)

  File "/usr/lib/python2.4/site-packages/django/views/admin/main.py", line 134, in change_list
    lookup_order_field = '%s.%s' % (f.rel.to.db_table, f.rel.to.ordering[0])

IndexError: list index out of range

MODEL Excerpt

class Agencytype(meta.Model):
    name = meta.CharField(maxlength=32)
    creation_date = meta.DateTimeField(auto_now_add=True)
    last_modified = meta.DateTimeField(auto_now=True)

    def __repr__(self):
        return self.name

    class META:
        admin = meta.Admin(
                    list_display = (
                        "name", 
                        "creation_date", 
                        "last_modified"
                        )
                    )
 
class Agency(meta.Model):
    name = meta.CharField(maxlength=32)
    type = meta.ForeignKey(Agencytype) 
    creation_date = meta.DateTimeField(auto_now_add=True)
    last_modified = meta.DateTimeField(auto_now=True)

    def __repr__(self):
        return self.name

    class META:
        unique_together = (("name", "type"),)
        admin = meta.Admin(
                    list_display = (
                        "name", 
                        "type", 
                        "creation_date", 
                        "last_modified"
                        )
                    )

Change History (5)

comment:1 Changed 9 years ago by adrian

  • Description modified (diff)

(Fixed formatting)

comment:2 Changed 9 years ago by adrian

  • Status changed from new to assigned
  • Summary changed from MySQL foreign key issues inside admin interface to Admin changelist assumes ForeignKey related object has ordering set

comment:3 Changed 9 years ago by adrian

  • milestone set to Version 1.0

comment:4 Changed 9 years ago by adrian

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

(In [693]) Fixed #469 -- Admin changelist no longer assumes ForeignKey has 'ordering' set when ordering by a ForeignKey field

comment:5 Changed 8 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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