Can I set make a Wagtail ImageField
only accept images of of certain dimensions ?
Asked
Active
Viewed 997 times
1

SergeyLebedev
- 3,673
- 15
- 29

Stuart Axon
- 1,844
- 1
- 26
- 44
-
Yes -- see https://gist.github.com/ag-castro/88bd803a43ed80f978453d76b4e7b890 – Mark Chackerian Mar 21 '20 at 02:02
1 Answers
0
Don't know if it's possible, but you can do something like this to restrict uploading images of large sizes:
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

Alexey
- 1,366
- 1
- 13
- 33