djongo icon indicating copy to clipboard operation
djongo copied to clipboard

Passing ContentFile to ImageField in a Model embedded into an ArrayField result in "Raw content" string value

Open weresobayes opened this issue 4 years ago • 0 comments

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.

weresobayes avatar Nov 01 '21 07:11 weresobayes