On Fri, 2006-08-11 at 21:56 +1000, Malcolm Tredinnick wrote: <snip>
> In fact, despite you giving me all this extra information (thanks!), now > that I'm concentrating, it's actually a little bit clearer what the > problem is. The order_by(...) clause is a little inconsistent with the > other query constructs. If you want to join with another table's field, > just use a period as the separator (see > http://www.djangoproject.com/documentation/db_api/#order-by-fields ) > > So, I suspect that > > return self.order_by('-photo.rating') > > should work for you (or at least come closer: again, looking at the > generated SQL is often very helpful when debugging these sorts of > things). > > I realise the above seems a bit counter-intuitive and it's a bit hidden > in the documentation. I'm not really sure what the solution is to that > beyond recommending that people read the docs *really* carefully (which > adds a bit to the learning curve). I'd forgotten about this subtlety > when I was reading your initial post this morning, so apologies for the > request for all this extra information I probably didn't need. Ahh! So simple! I'll admit I didn't find that part in the docs, I guess I subconsciously assumed I needed the double underscore. I got it all working by changing the manager to: class AlbumPhotoManager(models.Manager): def top_rated(self): return self.select_related().order_by('-albums_photo.rating') I had to prefix the table with the app name (as per docs), and also had to use select_related() since the default queryset didn't have the related fields selected. Thanks again Malcolm, your help is much appreciated. Cheers, Nick P.S. Also nice to see Django is well represented down under :-) --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---