1👍
✅
Firstly, you must use get
not filter
in your original query to get the Document:
obj = Document.objects.get(pk=document_id)
because filter
always returns a queryset, even if there is only one matching object.
Now you have obj
, you can just use the normal dot notation to get the attribute:
obj.labelled_image
This returns the relevant instance of LabelModel, and obj.labelled_image.image
will return the value of the file field.
Source:stackexchange.com