假设我有这些模型:
class RegionPage(models.Model):
area = models.ForeignKey('Area')
title = models.CharField(max_length=255)
class SomePage(models.Model):
someotherfield = models.ForeignKey('SomeClass')
title = models.CharField(max_length=255)
class Link(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntergerField()
content_object = GenericForeignKey('content_type', 'object_id')
title = models.CharField(max_length=255)
显然,我既不能使用select_related
也不能使用prefetch_related
来访问某些其他字段和区域字段。但是,在使用通用外键时,有没有办法减少查询量?