Hello,
in my ModelForm I try to allow only images (for avatar) smaller than
64*64 pixels. I've done this by overriding clean_avatar(). But how can
I check the dimensions? The instance is an InMemoryUploadedFile which
has no width or height. Any help regarding this?
class UserProfileForm(ModelForm):
class Meta:
model = UserProfile
exclude = ('user',) # User will be filled in by the view.
def clean_avatar(self):
img = self.cleaned_data['avatar']
if img.size > 10000: # working fine!
raise forms.ValidationError("Filesize too big. Max. 10k")
if img.width > 64: # 'InMemoryUploadedFile' object has no
attribute 'width'
raise forms.ValidationError("Not more than 64*64 pixels.")
return img
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---