Re: Ordering a queryset on a reverse foreign key's attribute
From a quick look I'd also expect `order_by('-children__date')` to work.
Can you provide the generated SQL query and some results?
Le jeudi 1 août 2013 09:58:25 UTC-4, Daniele Procida a écrit :
I have an Event model:--
class Event(Model):
parent = models.ForeignKey('self', related_name='children')
date = models.DateField()
My question is: given a queryset of this model, how can I order it based on the Events' children's dates so that (say) Events with child Events with more recent dates are first?
(I thought that
.order_by('-children__date')
might be a start, but in fact that seems to do something very odd to the items in the list, which I am looking at separately).
Thanks,
Daniele
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home