Cleaner, shorter "order_by" and "ordering" syntax

60 views
Skip to first unread message

Adrian Holovaty

unread,
Jul 20, 2005, 1:59:34 AM7/20/05
to django-d...@googlegroups.com
Instead of the following:

ordering = (('pub_date', 'ASC'), ('name', 'DESC'), ('other',
'RANDOM'))

What do you think of this syntax?

ordering = ('pub_date+', 'name-', 'other?')

This syntax would be used when declaring default ordering in models
(via the "ordering" argument), and it'd be used in the "order_by"
parameter to the database API.

I like it because it's a lot less crufty, easier to type and easier to
read.

The change can even be backwards-compatible if we wanted it to be,
although I'd want to phase out the old-style ordering eventually.

Thoughts?

Adrian

Matthew Marshall

unread,
Jul 20, 2005, 3:53:32 PM7/20/05
to django-d...@googlegroups.com
I really like it. It is much less error prone.

MWM

deelan

unread,
Jul 21, 2005, 10:33:53 AM7/21/05
to django-d...@googlegroups.com

Adrian Holovaty wrote:
> Instead of the following:
>
> ordering = (('pub_date', 'ASC'), ('name', 'DESC'), ('other',
> 'RANDOM'))
>
> What do you think of this syntax?
>
> ordering = ('pub_date+', 'name-', 'other?')

> The change can even be backwards-compatible if we wanted it to be,
> although I'd want to phase out the old-style ordering eventually.
>
> Thoughts?

similar to SQLObject, where IIRC you can declare a DESC order using
order_by='-pub_date'. you could imply a ASC order (that is without the
the + at the end).

go for it, adrian.

-- deelan.

pbx

unread,
Jul 21, 2005, 10:13:20 PM7/21/05
to django-d...@googlegroups.com

Nice. Seems like it would make sense to follow the lead of SQLObject
here, prepending a "-" for descending order. It has the advantage of
making sense mathematically as well.

pb

Reply all
Reply to author
Forward
0 new messages