class Item(meta.Model):
...
file = meta.FileField(upload_to="files",blank=True)
...
def _post_save(self):
path = self.get_file_filename()
im = Image.open(path)
im.thumbnail((128,128))
(p1,p2) = path.split('.')
im.save(p1+"_tn."+p2)
What I found is everytime I do "add item" in admin interface,
self.get_file_filename() returns the path of MEDIA_ROOT, not the full
path of the image file uploaded. How to solve this problem? Thanks in
advance.
Hey Sam,
This is happening because of a bug -- if you use a FileField,
_post_save() is called twice: once for the object itself, then again
to save the file-upload information.
I haven't tested this, but you may be able to hack around the problem
by checking whether self.file has been set. If it's been set, then do
the image resizing, etc. If it hasn't been set yet, it's the first
time through _post_save() and you shouldn't do anything.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com