例如:
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class Container(models.Model):
pass
class StoredUnit(models.Model):
container = models.ForeignKey( Container )
content_type = models.ForeignKey( ContentType )
object_id = models.IntegerField()
content_object = generic.GenericForeignKey()
class UnitA(models.Model):
name = models.CharField()
stored_unit = generic.GenericRelation( StoredUnit )
class UnitB(models.Model):
name = models.CharField()
stored_unit = generic.GenericRelation( StoredUnit )
给定一个容器,是否可以跨通用关系按字段对“单元”进行排序?
e.g.
container.storedunit_set.order_by('<genericly_related_unit>__name')