What exactly does order_with_respect_to do?

1,336 views
Skip to first unread message

Continuation

unread,
Nov 29, 2009, 7:50:05 PM11/29/09
to Django users
In the doc (http://docs.djangoproject.com/en/dev/ref/models/options/
#order-with-respect-to) it is mentioned that order_with_respect_to
marks an object as "orderable" with respect to a given field.

What exactly does that mean? Can someone give me an example of how
this could be used?

The doc's example is:
order_with_respect_to = 'question'

How is that different from
ordering = ['question']


anentropic

unread,
Nov 30, 2009, 5:14:04 AM11/30/09
to Django users
I've been wondering this too, the docs aren't clear.

Preston Holmes

unread,
Nov 30, 2009, 4:20:53 PM11/30/09
to Django users
order_with_respect_to uses the Question classes' ordering, where just
ordering would use the string representation of that question.

So using the example of questions and answers from the docs

if Question had a 'sequence' field, and Question meta.ordering was set
to use sequence, the answers would use that sequence. If using
ordering instead of order_with_respect_to, then the questions would be
in alphabetical question order.

At least thats how I understand it.

-Preston

smcoll

unread,
Dec 15, 2009, 11:28:10 AM12/15/09
to Django users
This is probably a dead thread, but... i think the answer given is
incorrect.

'order_with_respect_to' adds an '_order' integer field to the model.
Each set of instances that share a parent object of the relation
specified by 'order_with_respect_to' get ordered as a set. So in the
example, three Answer instances with fk's to one Question instance
will have '_order' values of 0, 1, and 2, which represent their
(specified) ordering "with respect to" that Question instance.

i'd be curious to know if anyone has seen an admin implementation for
reordering with this field. i'd also heard some chatter a while back
that this might be removed in future releases of Django, because it
leans toward the "magic" end of things.

shannon

Hanne Moa

unread,
Dec 15, 2009, 1:54:12 PM12/15/09
to django...@googlegroups.com
2009/12/15 smcoll <smc...@gmail.com>:
> i'd be curious to know if anyone has seen an admin implementation for
> reordering with this field.  i'd also heard some chatter a while back
> that this might be removed in future releases of Django, because it
> leans toward the "magic" end of things

I always end up making an explicit field "pos" for this anyway. Fewer surprises.


HM
Reply all
Reply to author
Forward
0 new messages