【发布时间】:2011-02-25 17:48:43
【问题描述】:
select_related 是否适用于 GenericRelation 关系,或者是否有合理的替代方案?目前 Django 正在为我的查询集中的每个项目执行单独的 sql 调用,我想避免使用类似 select_related 的东西。
class Claim(models.Model):
proof = generic.GenericRelation(Proof)
class Proof(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
我正在选择一堆声明,我希望将相关的证明拉入而不是单独查询。
【问题讨论】:
标签: django django-orm