2014-04-10 64 views
0

這裏是我的代碼:重新調整使用PIL圖像中pre_save信號

from PIL import Image 
from pilkit.processors import ResizeToFit 

def before_saving_shop(sender, instance, **kwargs): 
    img = Image.open(instance.logo) 
    processor = ResizeToFit(100, 100) 
    instance.logo = processor.process(img) 

pre_save.connect(before_saving_shop, sender=Shop) 

我得到這個異常:

Exception Value: _committed 

請幫助。

+0

您必須發佈完整的堆棧跟蹤。只是例外值是無用的。 – Thomas

回答

0

你不需要使用信號來達到這個目的。只需重新定義Shop模型的保存方法,如下所示:

class Shop(models.Model): 
    .... 

    def save(self): 
     img = Image.open(self.logo) 
     processor = ResizeToFit(100, 100) 
     self.logo = processor.process(img) 
     super(Shop, self).save()