Ticket #1245: admin_views_main.diff

File admin_views_main.diff, 936 bytes (added by Jorge Gajon <gajon@…>, 19 years ago)

Fix lookup_order_field for OneToOne fields

  • django/contrib/admin/views/main.py

     
    199199        except meta.FieldDoesNotExist:
    200200            pass
    201201        else:
    202             if isinstance(lookup_opts.get_field(order_field).rel, meta.ManyToOneRel):
    203                 f = lookup_opts.get_field(order_field)
     202            f = lookup_opts.get_field(order_field)
     203            if isinstance(f.rel, meta.OneToOneRel):
     204                lookup_order_field = '%s' % (f.column,)
     205            elif isinstance(f.rel, meta.ManyToOneRel):
    204206                rel_ordering = f.rel.to.ordering and f.rel.to.ordering[0] or f.rel.to.pk.column
    205207                lookup_order_field = '%s.%s' % (f.rel.to.db_table, rel_ordering)
    206208        # Use select_related if one of the list_display options is a field with a
Back to Top