This code should work with Django 1.0 :
from django.db import models
from PIL import Image
class Photo(models.Model):
related_entry_id = models.ForeignKey(MyBlogEntryModel) # Use your
model object
photo = models.ImageField(upload_to="my_upload_path/") # Point to
your upload directory (No leading slash will point to a subfolder of
your media root)
def __str__(self):
return "%s" % (
self.photo.name)
def _save_FIELD_file(self, field, filename, raw_contents,
save=True):
filename = "%s_%s" % (self.related_entry_id, filename)
super(Photo, self)._save_FIELD_file(field, filename,
raw_contents, save)
def save(self, size=(800, 800)):
if not
self.id and not self.photo:
return
super(Photo, self).save()
filename = self.photo.path
image = Image.open(filename)
image.thumbnail(size, Image.ANTIALIAS)
image.save(filename)
On Oct 3, 5:43 pm, "Juanjo Conti" <
jjco...@gmail.com> wrote:
> Matt, I'd like to resize an uploaded image, while uploading i think...
> before it gets saved to the hard disk. How did you do it? In pre 1.0
> version I redefined _save_FIELD_file from my class.
>
> Thanks,
>
> 2008/8/14 mcordes <
cordes.matt...@gmail.com>: