订阅django中的通用关系

时间:2011-03-30 09:40:46

标签: django sql-order-by contenttype generic-relationship

例如:

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') 

0 个答案:

没有答案