Brant Harris wrote:
I'm not really sure if this is known (is there a ticket?), but I'd bet
that this problem will be cleared up after the magic removal branch
goes trunk.

Hopefully. This likely a little bug in contrib/admin/views/main.py.

- If not specified by model, row selection list by default will sort by primary key field. - Ordering a ForeignKey or OneToOneField also got special treatment, where it will be sorted by its related field (on the other table).

But there seems to be an assumption that ordering a foreign key only happens if user defined admin's meta list_display parameter, which automatically force select_related=True parameter. The same error could easily be triggered when user defined any foreign key as the default ordering, ie: meta.Admin(ordering=('poll',)) where poll is a foreign key.

Temporary fix can be applied by passing list_select_related=True
..
   class META:
       admin = meta.Admin(list_select_related=True)
..

A perhaps more permanent fix is applying this patch:

Index: django/contrib/admin/views/main.py
===================================================================
--- django/contrib/admin/views/main.py    (revision 1827)
+++ django/contrib/admin/views/main.py    (working copy)
@@ -203,6 +203,7 @@
                f = lookup_opts.get_field(order_field)
rel_ordering = f.rel.to.ordering and f.rel.to.ordering[0] or f.rel.to.pk.column lookup_order_field = '%s.%s' % (f.rel.to.db_table, rel_ordering)
+                lookup_params['select_related'] = True
# Use select_related if one of the list_display options is a field with a
        # relationship.
        if lookup_opts.admin.list_select_related:


--
 dsw




Reply via email to