On 1/24/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote:
>
> Waylan Limberg wrote:
> > On 1/24/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote:
> >> Book.objects.all().select_related()
> >> .order_by('-bookshop_bookstat.avg_rating')[0:10]
> >>
> >
> > You should replace the dot (.) with a double underscore (__), so:
> >
> > .order_by('-bookshop_bookstat__avg_rating')[0:10]
>
> Sadly enough no go either, this gives me:
> "column bookshop_book.bookstat__avg_rating does not exist"
>
Hmm, you shouldn't have any dots in there, and this looks different
that your earlier examples. Perhaps you should check the docs [1].
I should also note that in the example I gave, I did not look at you
models. Now that I have, it seems you are confused more than I
originally thought. You don't need to refer to each model, just
follow the relationship with double underscores. try:
Book.objects.all().select_related().order_by('-book__avg_rating')[0:10]
Actually, as you have `related_name` set (to 'stats'), I believe this
may be what you want:
Book.objects.all().select_related().order_by('-stats__avg_rating')[0:10]
[1]:
http://www.djangoproject.com/documentation/db_api/#lookups-that-span-relationships
--
----
Waylan Limberg
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
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=en
-~----------~----~----~----~------~----~------~--~---