Conditionally Require Only One Field In Django Model Form

django, forms, model, python, validation

Solution

Override .clean(self) method, check for self.cleaned_data and raise ValidationError

https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

Problem

Anyway to make a field conditionally required based on whether or not another field in the same form has been filled out? ``` If field1 has no data, but field2 does form is valid. ``` ``` If field1 has no data and field2 has no data form is invalid ``` Not looking for any javascript solutions. I feel as it should be solved with django forms, but not quite sure how best to go about it.

Original source