django-image-kit更改管理员保存内的处理器值

时间:2012-02-24 12:36:16

标签: django image-resizing django-imagekit

我正在尝试使用带有管理员图片上传的图片工具包。在我的编辑表单中,有宽度和高度的字段。我需要一种方法将这些值传递给image-kit的处理器。

但是我找不到方法......?

1 个答案:

答案 0 :(得分:0)

答案是:
Imagekit版本是开发版本(2,0,0,'alpha',1) 假设我们在图像模型admin.py


此函数将用作可调用对象,实例为图像对象

def getThumb(文件,实例):     return [resize.ResizeToFill(width = instance.width,height = instance.height)]

类图像(媒体):
    width = models.IntegerField(blank = True,null = True)     height = models.IntegerField(blank = True,null = True)

file = models.ImageField(upload_to='static/uploads/images/bigs')  
### IMAGE-KIT we are passing a callable function as processors to ImageSpecField 
thumbnail = ImageSpecField( processors = getThumb, image_field='file', format='JPEG', options={'quality': 90}) 

### override admin save function
def save(self, *args, **kwargs):       
    # Call the "real" save() method in the base class 'models.Model'        
    super(Image, self).save(*args, **kwargs) 
    test = Image.objects.all()[0]  
    test.thumbnail.width ### getting a property means completing upload of imagekit file