librelist archives

« back to archive

Wand Image to ImageField

Wand Image to ImageField

From:
Johnny W. Santos
Date:
2012-11-28 @ 13:52
Hello everyone.

I trying to do something like this:

>>> buffer = io.BytesIO()>>> with Image(file=self.attachment) as wand:
...     wand.save(file=buffer)>>> buffer.seek(0)>>> img = ImageFile(buffer)

This image will be saved in a model with ImageField, but when try access
the image by object.image this returns, <io.BytesIO object at 0x186d5f0>
and in admin dont show the file.

>>> Page.objects.create(image=image)>>> <Pagina: Página novoteste>>>> pg =
Page.objects.get(pk=7)>>> pg.image>>> <io.BytesIO object at 0x186d5f0>

Someone can help me with this?

-- 
Johnny W. dos Santos
<https://www.facebook.com/johnny.welll>
<https://twitter.com/#!/OSrJota>
<http://br.linkedin.com/pub/johnny-santos/32/386/381>

Re: Wand Image to ImageField

From:
Johnny W. Santos
Date:
2012-11-28 @ 14:30
Sorry, but in:

>>> with Image(file=self.attachment) as wand:

the correct form i was trying is:

>>> with Image(filename='file.jpg') as wand:


2012/11/28 Johnny W. Santos <johnny.w.santos@gmail.com>

> Hello everyone.
>
> I trying to do something like this:
>
> >>> buffer = io.BytesIO()>>> with Image(file=self.attachment) as wand:
> ...     wand.save(file=buffer)>>> buffer.seek(0)>>> img = ImageFile(buffer)
>
>
> This image will be saved in a model with ImageField, but when try access
> the image by object.image this returns, <io.BytesIO object at 0x186d5f0>
> and in admin dont show the file.
>
> >>> Page.objects.create(image=image)>>> <Pagina: Página novoteste>>>> pg
= Page.objects.get(pk=7)>>> pg.image>>> <io.BytesIO object at 0x186d5f0>
>
> Someone can help me with this?
>
> --
> Johnny W. dos Santos
> <https://www.facebook.com/johnny.welll>  
<https://twitter.com/#!/OSrJota> 
<http://br.linkedin.com/pub/johnny-santos/32/386/381>
>
>


-- 
Johnny W. dos Santos
<https://www.facebook.com/johnny.welll>
<https://twitter.com/#!/OSrJota>
<http://br.linkedin.com/pub/johnny-santos/32/386/381>