You can't order by a property of a model, but you can do that by the
field of the related model:
Film.objects.select_related().order_by('appname_product.name')

Documentation:
http://www.djangoproject.com/documentation/db_api/#order-by-fields

Regards,
Aidas Bendoraitis [aka Archatas]


On 2/16/07, Mae <[EMAIL PROTECTED]> wrote:
>
> Oh, I should mention that I do know about the extra clause, but I'd
> really like to use simple, more database-ignorant queries like
> all().order_by() for elegance and portability.  I just want them to
> work on loaded class instances, not raw database fields.
>
> Is this possible?
>
> On Feb 16, 11:48 am, "Mae" <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > I have a class Film that owns a Product:
> >
> > class Product(models.Model):
> >     name = models.CharField(maxlength=100)
> >
> > class Film(models.Model):
> >     product = models.ForeignKey(Product, unique=True)
> >
> > Film has a property "title" that corresponds to Product's "name":
> >
> >     def _getTitle(self):
> >         return self.product.name
> >     title = property(_getTitle)
> >
> > In my view, I'd like to do something like this:
> >     films = Film.objects.all().order_by('title')
> >
> > But "title" is a model property, not a database table field, and
> > order_by doesn't know to look for it.  I get the error:
> > (1054, "Unknown column 'projectname_film.title' in 'order clause'")
> >
> > I don't really want to write my own sorting routines...  Does anyone
> > know how to solve this without having to re-implement QuickSort?
> >
> > Mae
>
>
> >
>

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

Reply via email to