Hi. I already asked this question in StackOverflow, but I didn't get any useful answer. Let's try here :-)
I have a BaseInlineFormSet, and I'd like to validate a field in the parent form based on the values on the fields of the children. As seen in the docs, the only method to make a custom validation is clean(), but I can't find a way to add errors to the parent form, only for the children.
In the following code I build a formula. Each variable comes from a inner form, and if the global formula don't validate, I'd like to add an error to the parent's form field formula
class CustomInlineFormSet(BaseInlineFormSet):
def clean(self):
formula = self.instance.formula
variables = []
for form in self.forms:
if 'formula_variable' in form.cleaned_data:
variables.append(form.cleaned_data['formula_variable'])
valid, msg = validate_formula(formula, variables)
if not valid:
WHAT HERE???