我正在使用 ImageMagick 和绑定棒为 Django 中上传的图像生成缩略图。我可以很好地生成缩略图,但我不确定如何将图像对象从 ImageMagick 传递回 Django 模型。所以我有一个简化的模型如下:
from wand import Image
class Attachment(models.Model):
attachment = models.FileField(upload_to="some_path")
thumbnail = models.ImageField(upload_to="other_path")
def generate_thumb(self):
with Image(file=self.attachment) as wand:
thumb = wand.resize(width=50, height=50)
thumb.save(file=self.thumbnail)
这会在最后一行生成一个错误ValueError: The 'thumbnail' attribute has no file associated with it.
Is there a simple way to get a file object out of wand and into django without too much siliness?
谢谢。