Default sort order in admin

2,595 views
Skip to first unread message

Zeynel

unread,
Nov 16, 2009, 10:11:33 AM11/16/09
to Django users
Hi,

Is there a way to change the default sort order in admin of my sqlite
db? At this point it sorts the table in the order entered (last
entered item first).

Thanks

Karen Tracey

unread,
Nov 16, 2009, 10:22:48 AM11/16/09
to django...@googlegroups.com

Zeynel

unread,
Nov 16, 2009, 11:31:50 AM11/16/09
to Django users
Thanks!

I noticed that using

class Lawyer(models.Model):
...
ordering = ('last',)

did not work.

But this worked

class Lawyer(models.Model):
...
class Meta:
ordering = ('last',)

copied from http://www.djangoproject.com/documentation/models/ordering/


What is the correct way actually?


On Nov 16, 10:22 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Nov 16, 2009 at 10:11 AM, Zeynel <azeyn...@gmail.com> wrote:
> > Hi,
>
> > Is there a way to change the default sort order in admin of my sqlite
> > db? At this point it sorts the table in the order entered (last
> > entered item first).
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> Karen

Preston Holmes

unread,
Nov 16, 2009, 4:56:22 PM11/16/09
to Django users


On Nov 16, 8:31 am, Zeynel <azeyn...@gmail.com> wrote:
> Thanks!
>
> I noticed that using
>
> class Lawyer(models.Model):
>     ...
>     ordering = ('last',)
>
> did not work.
>
> But this worked
>
> class Lawyer(models.Model):
>     ...
>     class Meta:
>         ordering = ('last',)
>
> copied fromhttp://www.djangoproject.com/documentation/models/ordering/
>
> What is the correct way actually?

If you notice - you are looking at two ways of doing it, depending
whether you want the ordering to be applied to just the model
(django.models.Model) or the ModelAdmin
(django.contrib.admin.ModelAdmin).

regular models use Meta class for ordering - ModelAdmin classes use an
ordering attribute.

The modeladmin docs say : "If this isn't provided, the Django admin
will use the model's default ordering."

so they are both "correct"

-Preston

Daniel Roseman

unread,
Nov 16, 2009, 5:55:33 PM11/16/09
to Django users
On Nov 16, 4:31 pm, Zeynel <azeyn...@gmail.com> wrote:
> Thanks!
>
> I noticed that using
>
> class Lawyer(models.Model):
>     ...
>     ordering = ('last',)
>
> did not work.
>
> But this worked
>
> class Lawyer(models.Model):
>     ...
>     class Meta:
>         ordering = ('last',)
>
> copied fromhttp://www.djangoproject.com/documentation/models/ordering/
>
> What is the correct way actually?

You weren't reading closely enough. The page Karen linked you to is
all about admin options, and that option therefore belongs on the
ModelAdmin class, not the model itself. The other page explains how
you set the default ordering for a model throughout the application,
which the admin will also use if it doesn't have anything else set.
--
DR.

Zeynel

unread,
Nov 16, 2009, 8:17:09 PM11/16/09
to Django users
Yes, this is probably true. I am still learning. And I like Django and
how it works but it takes time to understand some concepts. I was
rushing a little bit because I wanted to meet this challenge

>> [the tutorial] is enough to build it in no longer that a few days (learning
>> included),
>> even for pre-intermediate programmer.

mentioned here:
http://groups.google.com/group/django-users/browse_frm/thread/d7f9320f3fba5df0/cfd37dc8d5d51027?q=#cfd37dc8d5d51027

But it took me 2 weeks to finish this very simple app.

And I'm still trying to resolve this last issue. If you look at the
pictures here http://zeynel.posterous.com/django-template-problem
the title "Search lawyer by last name" should not be in the /admin/
wkw1 directory because the search box is in /admin/wkw1/lawyer/.

How do I change that title?
Reply all
Reply to author
Forward
0 new messages