保存原始图像后如何填写ProcessedImageField?
保存原始图像后如何填写ProcessedImageField?
我尝试重写保存方法,如下所示:
class A(models.Model):
original = models.ImageField()
webp_1x = ProcessedImageField(format='WEBP', processors=[ResizeToFit(320, 320), null=True, blank=True)
webp_2x = ProcessedImageField(format='WEBP', processors=[ResizeToFit(640, 640)], null=True, blank=True)
def save(self, *args, **kwargs):
self.webp_1x = self.original
self.webp_2x = self.original
super().save(*args, **kwargs)
但它不起作用。 不幸的是,ProcessedImageField 中没有参数源
How do I fill in the ProcessedImageField after saving the original image?
I tried to override the save method, smth like this:
class A(models.Model):
original = models.ImageField()
webp_1x = ProcessedImageField(format='WEBP', processors=[ResizeToFit(320, 320), null=True, blank=True)
webp_2x = ProcessedImageField(format='WEBP', processors=[ResizeToFit(640, 640)], null=True, blank=True)
def save(self, *args, **kwargs):
self.webp_1x = self.original
self.webp_2x = self.original
super().save(*args, **kwargs)
But it doesn't work.
Unfortunately, there is no argument source in ProcessedImageField
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论