Hello,
I have a Tag model which has a Generic Foreign Key . I want to order a query on the Tag model by fields in related models (related via the Generic Foreign Key), for Example: >>> [ o.content_object for o in >>> Tag.objects.order_by('content_type__id','foo__name','bar__name') ] Gives me: [<Foo: aaa_foo>, <Foo: ttt_foo>, <Foo: xxx_foo>, <Bar: xxx_bar>, <Bar: ttt_bar>, <Bar: aaa_bar>] What i'm after is : [<Foo: aaa_foo>, <Foo: ttt_foo>, <Foo: xxx_foo>, <Bar: aaa_bar>, <Bar: ttt_bar>, <Bar: xxx_bar>] Any suggestions appreciated. Right now im looking at sorting the result of the Query Set in python which isn't ideal. I am using Django 1.1 Heres my model: from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class Tag(models.Model): # Content-object field content_type = models.ForeignKey(ContentType, verbose_name='content type', related_name="content_type_set_for_%(class)s") object_id = models.TextField('object ID') content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_id") class Foo(models.Model): tags = generic.GenericRelation(Tag, content_type_field='content_type', object_id_field='object_id' ) name = models.CharField(max_length=150) creation_date = models.DateTimeField(auto_now_add=True) class Meta: ordering = ['name',] def __unicode__(self): return self.name class Bar(models.Model): tags = generic.GenericRelation(Tag, content_type_field='content_type', object_id_field='object_id' ) name = models.CharField(max_length=150) creation_date = models.DateTimeField(auto_now_add=True) class Meta: ordering = ['name',] def __unicode__(self): return self.name Thanks Ant -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.