I'm attempting to check the 'image' field on my form to see if it's valid. Within my view, I've got the following code:
if form.is_valid():
#some stuff
else:
errors = form.errors.as_data()
for error in errors:
if error == 'image':
print('There was an error with the image!')
I have a custom validator that causes the form to not validate if the image that the user attempts to upload is > 5MB. When I upload an image > 5MB, I get the following error:
'EditUserProfileForm' object has no attribute 'image'
This form definitively has an 'image' field on it. It's a model form and the model also has an 'image' field. The user can successfully upload a photo if its less than 5MB, so its not anything else that's broken.
Edit: I've updated the else statement. The print statement works when there is an image error (i.e. it is over 5mb), but it doesn't seem possible to change the image field at this point in the code. I get an error message that indicates that "The UserProfile could not be changed because the data didn't validate" or "This QueryDict instance is immutable" whenever I try to change either the value on the model instance or the form value, respectively.
Changing the form value seems possible only in forms.py if the form didn't validate.