Hi

I have the following model, which is just for images and is edited
inline in a different model.

Before I added the def save(self) for the image thumbnail creating, I
could upload multiple images in the  Admin "Property" model in one go.
But now i want to resize each image, and this works if I upload the
image via the PropertyImage model, but if i do it via the Related
module "Property" I get an error.

What am i doing wrong? or why would this not work via edit inline?

Thanks!

#Model

class PropertyImage(models.Model):
        caption = models.CharField(maxlength=30, help_text="Displayed as the
cation and ALT tag.", core=True)
        sortOrder = models.IntegerField(null=True, blank=True,
verbose_name="Sort Order", help_text="0 to high number, 0 is displayed
1st.")
        imageheight = models.IntegerField(editable=False, null=True)
        imagewidth = models.IntegerField(editable=False, null=True)
        imagefile =
models.ImageField(upload_to='uploads',height_field='imageheight',width_field='imagewidth',help_text="Will
be resized to max 800 x max 800 pixel.")
        category = models.CharField(maxlength=3, choices=CATEGORY_CHOICES)
        property = models.ForeignKey(Property, edit_inline=models.TABULAR,
num_in_admin=8, min_num_in_admin=8, max_num_in_admin=15,
num_extra_on_change=1)
        def save(self):
                #Image resize to 800 x 800 (max) also stores new size in table.
                from PIL import Image
                IMAGE_RESIZE = (800, 800)
                image = Image.open(self.get_imagefile_filename())
                if image.mode not in ('L', 'RGB'):
                        image = image.convert('RGB')
                image.thumbnail(IMAGE_RESIZE, Image.ANTIALIAS)
                NEW_SIZE = image.size
                self.imageheight = NEW_SIZE[1]
                self.imagewidth = NEW_SIZE[0]
                image.save(self.get_imagefile_filename())
                #finish image resize
                super(PropertyImage, self).save()
        def __str__(self):
                return self.imagefile
        class Admin:
                pass

Error:
IOError at /admin/Property_Management/property/3/
[Errno 2] No such file or directory: ''
Request Method:         POST
Request URL:    http://192.168.1.2:8080/admin/Property_Management/property/3/
Exception Type:         IOError
Exception Value:        [Errno 2] No such file or directory: ''
Exception Location:     C:\Python25\Lib\site-packages\PIL\Image.py in
open, line 1888
Python Executable:      c:\python25\python.exe
Python Version:         2.5.0

Variable        Value
IMAGE_RESIZE    (800, 800)
Image   <module 'PIL.Image' from 'c:\python25\lib\site-packages\PIL
\Image.pyc'>
self    <PropertyImage: >


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

Reply via email to