Reputation: 6768
I have four models:
Task(models.Model):
fields...
BasicImage(models.Model):
task = models.ForeignKey(Task)
fields...
VisImage(BasicImage):
fields...
IRImage(BasicImage):
fields...
Later I have code that does the following:
task = Task.objects.get()
basicimages = task.basicimage_set.select_related().all()
imageset1 = basicimages.filter(filter=1)
imageset2 = basicimages.filter(filter=2)
and in a template, I end up displaying the information like so:
{% for i in imageset1 %}
{{ i.visimage.field }}
{% endfor %}
{% for i in imageset2 %}
{{ i.irimage.field %}
{% endfor %}
However, according to the Django Debug toolbar (and the obvious lag), Django is still requerying for each .visimage and .irimage object. How come select_related isn't taking care of this?
Upvotes: 0
Views: 114
Reputation: 29511
model inheritance adds a implicit one-to-one field on the subclass model. as much as i know, select_related doesn't work for reverse relations.
Upvotes: 1