I'd love to pitch in on updating the docs for file handling :)

Even though this kind of talk is better suited over on django-users,  here's
one way to skin a cat.
I had a view that displayed a model form (one of the fields was a
FileField).  I needed to alter the resolution of the uploaded image to make
sure it wasn't HUGE.

http://dpaste.org/oN2J/

In my case, I was resizing the original image *after* it had been stored
according to the file field's upload_to settings.
The 'image' I got from the form is basically a file object (
http://docs.djangoproject.com/en/dev/ref/files/file/) which is what I
tripped up on at first when putting this together.  You have to make sure
whatever you pass to ImageField as "contents" is an object that implements
that "File" interface, so to speak.  In the case of the upload from the
form, this was done for us, but if you have some random file on the
filesystem, you'd do something like this:

from django.core.files import File

tmpfile = File(open('/tmp/some-pic.jpg','rb'))
object.image.save('pic.jpg', tmpfile, save=True) # copy the image to
it's proper location and save the model instance when done.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to