I use polymorphic for two models in django, one of them has a one to one relation to another model.
from polymorphic.models import PolymorphicModel
class Base(PolymorphicModel):
name = models.CharField(max_length=25)
class Engine(models.Model):
name = models.CharField(max_length=25)
class A(Base):
type = models.CharField(max_length=25)
class B(Base):
name = models.CharField(max_length=25)
engine = models.OneToOneField(Engine)
class Host(Base):
base_type = models.ForeignKey(Base)
Now, I want to use prefetch_related for class Host
host = Host.objects.all().prefetch_related('base_type__engine__name')
But, It's not valid for some objects from model B.
Is there any way to prefetch Engine object when I fetch A object?