Show that form.is_valid works inside the Form's post_validation handler.
@@ -185,8 +185,14 @@ class Meta:
@staticmethod
def post_validation(form, **_):
# Notice that post_validation is run, even if there are invalid fields
- # hence the 'or' below
- if (form.fields.name.value or '').lower() == "tomato" and form.fields.color.value == "Blue":
+ # So you either have to check that fields that you are interested in
+ # are not None
+ # Or alternatively if you ony want to run your validation if all fields
+ # passed their individual checks you can just call form.is_valid (see below).
+ # BUT when form.is_valid is called outside of a Form's post_validation
+ # handler its result includes errors caused by the post_validation (as you
+ # would expect).
+ if form.is_valid() and form.fields.name.value == "tomato" and form.fields.color.value == "Blue":
# Or alternatively call form.add_error
raise ValidationError("Tomatoes are not blue")
