Re: order_by related models

2009-11-17 Thread dave.l
Hi Karen,

Thank you!  I was just being blind -- I'd looked at that paragraph and
the double underscore just went in one eye and out the other and
didn't register as being different to the old format...

doh.

--

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




Re: order_by related models

2009-11-16 Thread Karen Tracey
On Mon, Nov 16, 2009 at 5:41 PM, dave.l
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 django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




order_by related models

2009-11-16 Thread dave.l
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

I have looked at the source, and it appear that if I could use "
app_building.`principal_name` " (i.e. with 'backticks') it would work.
but these are rejected by the regexp match.

Please could someone point me in the right directions.

Thanks,

--

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