Monday, November 29, 2010

Django admin photo upload

Hi all,

So, I am back once more. I am having headaches with a simple file upload in the Django admin.

I have a simple model as follows (partial):

class PhotoTest(models.Model):
     test_name = models.CharField(max_length=50)
     photo = models.ImageField(upload_to='testphotos', blank=True)
     thumbnail = models.ImageField(upload_to='thumbnails', blank=True)

I wish to find out how to override the save() method of this model so that, when a user selects a photo, I can read that image out of wherever it is in memory. I would like to thumbnail it with PIL,
assign it to the thumbnail field of the PhotoTest instance and finally, save it.

My problem is that I can not figure out where to read the original image from. Trying to read it from self.photo.path in the model's save() method does not work (object does not have path property).

Perhaps what I should be asking is, which attribute or method of the ImageField property allows me to access the selected file as a PIL File object?

Please help?

--
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

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

No comments:

Post a Comment