You have the right idea, but the problem is that separate field checks were already done before the form was clean. You have a couple of options. You can make the field unnecessary and process the logic when necessary in your form.clean . Or you can leave the field as necessary and remove validation errors that it can raise in its purest form.
def clean(self): cleaned_data = self.cleaned_data some_field = cleaned_data.get("some_field") if some_field == 'some_value': if 'other_field' in self.errors: del self.errors['other_field'] cleaned_data['other_field'] = None return cleaned_data
This has some problems in that it removes all errors, not just missing / necessary errors. There is also a problem with cleaned_data . Now you have a required field that is not in cleaned_data, so I added it as None . The rest of your application will need to handle this case. It may seem odd to have a required field that doesn't matter.
Mark lavin
source share