On Mon, Nov 16, 2009 at 5:41 PM, dave.l
<[email protected]>wrote:

> Hi!
>
> The following line in my application seems to have stopped working as
> I expect:
>
>   for object in self.queryset.select_related().order_by
> ("app_building.principal_name", "reference"):
>
> the first ordering term on principal_name is no longer working.  by
> looking at ...query.as_sql() I can see the ORDER BY is not being
> added.
>
> According to the docs:
>
>   New in Django 1.0: Please, see the release notes
>
>   The syntax for ordering across related models has changed. See the
> Django 0.96 documentation for the old behaviour.
>
> but I cannot find any reference to the new syntax
>


 From a couple of paragraphs above that note, in the description of order_by
here:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields

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. For
example:

Entry.objects.order_by('blog__name', 'headline')

Karen

--

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


Reply via email to