On Apr 10, 1:40 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> 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
Thanks! That did it - reading up on that method now.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---