Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#469 closed defect (fixed)

Admin changelist assumes ForeignKey related object has ordering set

Reported by: oliver.andrich@… Owned by: Adrian Holovaty
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: no UI/UX: no

Description (last modified by Adrian Holovaty)

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 by Adrian Holovaty, 19 years ago

Description: modified (diff)

(Fixed formatting)

comment:2 by Adrian Holovaty, 19 years ago

Status: newassigned
Summary: MySQL foreign key issues inside admin interfaceAdmin changelist assumes ForeignKey related object has ordering set

comment:3 by Adrian Holovaty, 19 years ago

milestone: Version 1.0

comment:4 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: assignedclosed

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

comment:5 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

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