I have a situation wherein a large number of objects of a particular class are being iterated over, and they take a huge amount of time for processing because I can't pre-select data using select_related
.
The class in question goes something like below
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Offer(models.Model):
...
object_id = models.PositiveIntegerField(db_index = True)
content_type = models.ForeignKey(ContentType, db_index = True)
content_object = generic.GenericForeignKey('content_type', 'object_id')
...
I have tried using select_related like below, but it obviously doesn't work
offerList = Offer.objects.select_related('content_type', "content_object"
).filter(content_type=ContentType.objects.get_for_model(SomeObject),
object_id=someobject.id)
So, how can I use select_related
with GenericForeignKey in django?