Forgive me if this has been answered before, I couldn’t find an answer where the validation depended on the aggregate of inline forms.
Little background: I’m doing a site for an insurance broker which has ‘Policies’ and a ‘Total Commission’ of that policy. There are also ‘Resellers’ which are added to the ‘Policy’ along with a commission which goes to them (can have any number of resellers). The total commission between the resellers has to be less than the total commission.
I have an admin.ModelForm for a policy, and below I have a admin.InlineTabular which can have multiple resellers through the ‘Add’ button and this all works perfectly.
However, I can’t seem to figure out how to do validation on them, so that I can basically add up all the commissions and then if it is greater than the total commission throw a ValidationError.
I’ve tried clean() but don’t know how to access the InlineTabular cleaned data if it is even available!
Thanks in advance for any help!
Thomas
I know the question was asked a long time ago, but since I struggled with the same problem, I think it might be usefull.
The key here is to define a custom formset to embed into the tabular admin form, then to override the formset clean’s method.
Here’s an example : a composition is made of composition_elements, each composition_element has a percent field, and I want to validate that the total percent is equal to 100.