Thursday, June 24, 2010

Re: Sorting objects according to a field from a foreign field

On Jun 22, 4:48 pm, Benedict Verheyen <benedict.verhe...@gmail.com>
wrote:
> On 22/06/2010 16:42, Daniel Roseman wrote:
>
>
>
> > As described in the documentation [1], you use the double-underscore
> > syntax for sorting across relationships.
> >     Call.objects.all().order_by('-priority__weight')
>
> > [1]:http://docs.djangoproject.com/en/1.2/ref/models/querysets/#order-
> > by-fields
> > --
> > DR.
>
> Thanks for the quick response.
> Hhhm, i searched the docs and didn't see it.

Quote: "To order by a field in a different model, use the same syntax
as when you are querying across model relations. That is, the name of
the field, followed by a double underscore (__), followed by the name
of the field in the new model, and so on for as many models as you
want to join." (5th para under the "order_by" section)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment