Opened 17 years ago

Closed 17 years ago

#6929 closed (invalid)

admin interface ignores multi-column ordering if it is set by default in the model

Reported by: shamardin@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Even if there are several fields specified for ordering by default in Meta ordering or Admin ordering, the resulting view in the admin interface is ordered only by the first field.

How to reproduce:

Create a new app with these models.py:

from django.db import models

class Test(models.Model):
  a = models.CharField(max_length=5)
  b = models.CharField(max_length=5)

  def __unicode__(self):
    return 'a=%s,b=%s' % (self.a, self.b)

  class Meta:
    ordering = ['-b', '-a']

  class Admin:
    pass

Populate with test data from shell:

In [1]: from test.models import *

In [2]: t1 = Test(a='1', b='10')

In [3]: t2 = Test(a='2', b='10')

In [4]: t3 = Test(a='1', b='11')

In [5]: t4 = Test(a='2', b='11')

In [6]: t1.save()

In [7]: t2.save()

In [8]: t3.save()

In [9]: t4.save()

Observe the correct ordering:

In [10]: Test.objects.all()
Out[10]: [<Test: a=2,b=11>, <Test: a=1,b=11>, <Test: a=2,b=10>, <Test: a=1,b=10>]

Now browse the Test model in the admin interface and observe the incorrect ordering:

a=1,b=11
a=2,b=11
a=1,b=10
a=2,b=10

Change History (1)

comment:1 by Ramiro Morales, 17 years ago

Resolution: invalid
Status: newclosed

This is intended and documented behavior. See the bottom of the relevant documentation section (http://www.djangoproject.com/documentation/model-api/#ordering)

Note: See TracTickets for help on using tickets.
Back to Top