#2883 closed defect (worksforme)
path is blank in an image field when using a save hook
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | major | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
def resizeThis(self):
img = pImage.open(self.path)
cImgSize = img.size
newH = int((500*cImgSize[1])/cImgSize[0])
img2 = img.resize((500, newH), pImage.ANTIALIAS)
img2.save(self.path)
def save(self):
super(Image, self).save()
self.resizeThis()
When I try this i get an IO Error and I'm not sure if it's a defect or not. It says self.path is empty for the image field in the model.
Change History (2)
comment:1 by , 18 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
I mean
class Image(models.Model): def resizeThis(self): img = pImage.open(self.path) cImgSize = img.size newH = int((500*cImgSize[1])/cImgSize[0]) img2 = img.resize((500, newH), pImage.ANTIALIAS) img2.save(self.path) saved_once=False def save(self): if self.saved_once: self.resizeThis() else: self.saved_once=True super(Image, self).save()
Note:
See TracTickets
for help on using tickets.
This is because of the way the addmanipulator works, it saves the model twice.