EDIT:
- I fixed a few typos below
- I added a zip file to a small app to demonstrate this problem here. You can download it and run python manage.py testselectrelateddefer after you syncdb and migrate.
- I added a couple of observations below
I fix I am having a multi-table inheritance model as following:
class Image(models.Model):
# other fields are removed for simplicity
image = models.ImageField(upload_to="image")
class ItemImage(Image):
# other fields are removed for simplicity
display_name = models.CharField(max_length=50)
I want to query this model and defer the image field when I don't need the image (which is in the parent model). My container model looks somewhat like this:
class Item(models.Model):
item_image = models.OneToOneField(ItemImage)
The query looks like this:
test.models.Item.objects.select_related('item_image').defer("item_image__image").get(pk=1)
Django is throwing an error saying:
ValueError: u'image_ptr_id' is not in the list.
Django does not throw an error if I query for the field that is not in the parent model:
test.models.Item.objects.select_related('item_image').defer("item_image__display_name").get(pk=1)
Do you know how to fix this issue?
Observations:
- As I mentioned above, this only happens if the deferred field is in the parent model; it does not happen if the deferred field is in the child model.
- It does not matter if the parents field have any extra field.