a ImageField能否受图像尺寸限制

斯图尔特·阿克森(Stuart Axon)

我可以设置为Wagtail ImageField仅接受某些尺寸的图像吗?

阿列克谢

不知道是否可能,但是您可以执行以下操作来限制上传大尺寸的图片:

from wagtail.wagtailadmin.forms import WagtailAdminPageForm


class BlogPageForm(WagtailAdminPageForm):

    def clean(self):
        cleaned_data = super().clean()

        if (cleaned_data.get('image') and somehow_check_if_img_to_large():
            self.add_error('image', 'Error! image is to large!')

        return cleaned_data


class BlogPage(Page):
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    description = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('photos'),
        FieldPanel('description')
    ]
    base_form_class = BlogPageForm

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章