鹡鸰ImageField可以被图像尺寸限制吗

Can a wagtail ImageField be restricted to by image dimension

我可以设置 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