On Saturday 06 May 2006 12:55, Brian Elliott wrote:

> Is it possible to order a query by a ManyToManyField?  For example,
> in the models below, I'd like to select all Entries and order by the
> Author's name.  Something to the effect of Entry.objects.all
> ().order_by('authors__name')?
>
> Thanks,
> Brian
>
> class Author(models.Model):
>      name = models.CharField(maxlength=50)
>      email = models.URLField()
>
> class Entry(models.Model):
>      headline = models.CharField(maxlength=255)
>      body_text = models.TextField()
>      pub_date = models.DateTimeField()
>      authors = models.ManyToManyField(Author)

I can't see how this would work -- an entry can have many authors, so 
which one do you order by?

The test of whether it can be included as a feature in the Django ORM is 
whether you can do it in SQL, and do it in a generic way.

Luke

-- 
"It is a truth universally acknowledged, that a single man in 
possession of a good fortune, must be in want of a wife." (Jane Austen)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

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

Reply via email to