﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8682	Admin ordering works incorrectly if ModelAdmin.ordering has several fields, and one of them is an another Model field	Ilya Semenov	nobody	"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]."		closed	contrib.admin	dev		invalid	newforms-admin admin ordering		Unreviewed	0	0	0	0	0	0
