Hello,
i use ImageWithThumbnailField to upload screenhots. In the save method i want
to set some additional model fields, like filesize and width/height of the
uploaded image. The problem is, that self.image isn't defined at this point,
the same entry has to be saved twice in the admin.
Checking for self.image (like i read in another thread) doesn't work for me.
Is there any way to get around this problem?
# -----------------------------
class Screenshot(models.Model):
image = ImageWithThumbnailField(upload_to='upload/screenshots/')
filesize = models.PositiveIntegerField(null=True, blank=True,
editable=False)
width = models.PositiveSmallIntegerField(null=True, blank=True,
editable=False)
height = models.PositiveSmallIntegerField(null=True, blank=True,
editable=False)
def get_image_path(self):
return '%s/%s' % (settings.MEDIA_ROOT, self.image)
def save(self):
super(Screenshot, self).save()
if self.image:
self.filesize = getsize(self.get_image_path())
img = Image.open(self.get_image_path())
self.width = img.size[0]
self.height = img.size[1]
--
Best Regards
Dirk Eschler <mailto:[EMAIL PROTECTED]>
http://www.krusader.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---