Django: select_related and GenericRelation
Posted
by Parand
on Stack Overflow
See other posts from Stack Overflow
or by Parand
Published on 2010-05-30T17:10:23Z
Indexed on
2010/05/30
17:12 UTC
Read the original article
Hit count: 193
django
|django-orm
Does select_related work for GenericRelation relations, or is there a reasonable alternative? At the moment Django's doing individual sql calls for each item in my queryset, and I'd like to avoid that using something like 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')
I'm selecting a bunch of Claims, and I'd like the related Proofs to be pulled in instead of queried individually.
© Stack Overflow or respective owner