djongo
djongo copied to clipboard
Passing ContentFile to ImageField in a Model embedded into an ArrayField result in "Raw content" string value
I'm creating a collection picture containing a field picture of a type ImageField. Collection picture would then be an embedded into an ArrayField pictures in collection product_pictures.
Here is the models:
class Picture(djongo_models.Model):
picture = djongo_models.ImageField()
class Meta:
abstract = True
class ProductPictures(djongo_models.Model):
product = djongo_models.CharField(max_length=10, null=False, primary_key=True)
pictures = djongo_models.ArrayField(model_container=Picture)
when saving a new instance I do the following:
product_pictures = ProductPicturesModel(product=pk)
product_pictures.pictures = [{"picture": picture}]
product_pictures.save()
In the above code picture is a Django ContentFile object. The resulting document from that operation is this.
{
"_id" : ObjectId("617f5f378a23c02e7c17fb7a"),
"product" : "oepG1Lq",
"pictures" : [
{
"picture" : "Raw content"
}
]
}
instead of saving the path of the content file, it also does not write the file. I'm certain this is not the expected behaviour, or I might be doing something wrong.