On Apr 10, 3:58 pm, Mojave <[EMAIL PROTECTED]> wrote:
> Given:
>
> class Topic(models.Model):
>         title = models.CharField(maxlength=200)
>         link = models.CharField(maxlength=200)
>
> class Item(models.Model):
>         topic = models.ForeignKey(Topic)
>         user = models.ForeignKey(User)
>
> I want to get a list of Items ordered by the title of their Topic:
>
> item_list = Item.objects.order_by('topics_topic.title')
>
> That's straight out of the 
> documentationhttp://www.djangoproject.com/documentation/db-api/#limiting-querysets
> but I get an exception: "Unknown table 'topics_topic' in order clause"

I believe the query on Item objects is not joining in your
topics_topic table at all. Try:

item_list =
Item.objects.select_related().order_by('topics_topic.title')

-Rajesh D

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to