From 9b68dbf95e10dd9af547176578e0e066aef8bdc5 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 25 Sep 2005 22:27:23 +0000 Subject: [PATCH] Fixed #469 -- Admin changelist no longer assumes ForeignKey has 'ordering' set when ordering by a ForeignKey field git-svn-id: http://code.djangoproject.com/svn/django/trunk@693 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/admin/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django/views/admin/main.py b/django/views/admin/main.py index f27985062a..e39f25c564 100644 --- a/django/views/admin/main.py +++ b/django/views/admin/main.py @@ -130,7 +130,8 @@ def change_list(request, app_label, module_name): lookup_order_field = order_field if isinstance(lookup_opts.get_field(order_field).rel, meta.ManyToOne): f = lookup_opts.get_field(order_field) - lookup_order_field = '%s.%s' % (f.rel.to.db_table, f.rel.to.ordering[0]) + 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) # Use select_related if one of the list_display options is a field with a # relationship. for field_name in lookup_opts.admin.list_display: