home / django_tickets / tickets

tickets: 8682

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8682 2008-08-29 12:39:15 2008-08-29 15:50:16 2022-03-06 03:42:53.961792 Unreviewed closed contrib.admin     dev invalid Admin ordering works incorrectly if ModelAdmin.ordering has several fields, and one of them is an another Model field If I create two dependent models, and ask the admin interface to order instances of the dependent Model based on the field of the base Model AND on its own field, the secondary ordering is lost. See minimalistic example: {{{ #!python class Foo(models.Model): is_active = models.BooleanField(default=True) class Bar(models.Model): foo = models.OneToOneField(Foo, primary_key=True) name = models.CharField(max_length=100) def __unicode__(self): return "%s, %s" % (self.name, "active" if self.foo.is_active else "inactive") # ... class BarAdmin(admin.ModelAdmin): list_display = ('name',) ordering = ('-foo__is_active', 'name') admin.site.register(Bar, BarAdmin) }}} {{{ insert into app_foo set is_active=1; insert into app_foo set is_active=1; insert into app_foo set is_active=1; insert into app_bar values (1,'aaaa'); insert into app_bar values (1,'ccc'); insert into app_bar values (1,'bbb'); }}} If we run a manual query, it works as expected: {{{ >>> Bar.objects.order_by('-foo__is_active', 'name') [<Bar: aaaa, active>, <Bar: bbb, active>, <Bar: ccc, active>] }}} However, the admin page at http://my.site/admin/app/bar/ would display: {{{ aaa ccc bbb }}} which means the ordering was lost. If both fields are in the same model, everything works fine. Django version is [8696]. nobody semenov newforms-admin admin ordering 0 0 0 0 0 0
Powered by Datasette · Queries took 43.586ms