#32679: Django model not updating image field correctly (Raw content)
-------------------------------------+-------------------------------------
     Reporter:  mcardozo             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  models               |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  1
-------------------------------------+-------------------------------------
Description changed by mcardozo:

Old 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`.

New 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 = MyModel.objects.get(pk=instance.pk)
 >>> mymodel.picture
 >>> <ImageFieldFile: Raw content>

 }}}

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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32679#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.2a764d712ca60b7ca2c727e266ec8412%40djangoproject.com.

Reply via email to