#8682: Admin ordering works incorrectly if ModelAdmin.ordering has several 
fields,
and one of them is an another Model field
-------------------------------------------+--------------------------------
 Reporter:  semenov                        |       Owner:  nobody    
   Status:  new                            |   Milestone:            
Component:  Admin interface                |     Version:  SVN       
 Keywords:  newforms-admin admin ordering  |       Stage:  Unreviewed
Has_patch:  0                              |  
-------------------------------------------+--------------------------------
 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].

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8682>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to