Opened 19 years ago
Last modified 18 years ago
#469 closed defect
MySQL foreign key issues inside admin interface — at Initial Version
Reported by: | 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
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"
)
)