Django

Code

Ticket #469 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

Admin changelist assumes ForeignKey related object has ordering set

Reported by: oliver.andrich@gmail.com Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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"
                        )
                    )

Attachments

Change History

09/12/05 22:25:34 changed by adrian

  • description changed.

(Fixed formatting)

09/12/05 22:32:39 changed 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.

09/25/05 17:18:16 changed by adrian

  • milestone set to Version 1.0.

09/25/05 17:27:24 changed by adrian

  • status changed from assigned to closed.
  • resolution set to fixed.

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

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted


Add/Change #469 (Admin changelist assumes ForeignKey related object has ordering set)




Change Properties
Action