Opened 3 years ago

Last modified 3 years ago

#32679 closed Bug

Django model not updating image field correctly (Raw content) — at Initial Version

Reported by: Marisol Cardozo Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords: models
Cc: cardozomarisolp@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My model:

class MyModel(models.Model):
    picture = models.ImageField(blank=True, null=True, upload_to='pictures')

Update a single object:

>>> picture
>>> <ContentFile: Raw content>
>>> mymodel = MyModel.objects.get(pk=instance.pk)
>>> mymodel.picture = picture
>>> mymodel.save()
>>> mymodel.picture
>>> <ImageFieldFile: pictures/fbdfe25b-b246-4f2d-9436-dca49aef88d7.png>

Good. Url result /media/pictures/fbdfe25b-b246-4f2d-9436-dca49aef88d7.png.

Update a single object with the update() method:

>>> picture
>>> <ContentFile: Raw content>
>>> MyModel.objects.filter(pk=instance.pk).update(picture=picture)
>>> mymodel.picture
>>> <ImageFieldFile: Raw content>

Bad. Url result: /media/Raw%20content.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top