Hi all,
I'm working on an application that uses a HTML-form consisting of multiple Django-ModelForms. Moreover, their validation is interdependent. Moreover, their data is interdependent. Moreover, I use multiple modelforms with the same instance (might be a bad idea anyway). My template looks something like this:
<form ...>
{% if forms.a %}
{{ forms.a }}
{{ forms.b }}
{# and much more of that #}
...
</form>
My view looks something like this:
if all([f.is_valid() for k, f in forms.items() if f is not None]):
if forms['a']:
a = forms['a'].save()
a.b = forms['b'].save()
a.b.c = forms['c'].save()
a.x = forms['d'].save(commit=false).x
a.save()
# and much more such stuff
...
Do you have any opinions/pointers on how to do this (most elegantly)? Especially how I can validate one form based on the (cleaned) data of another form? Or how you would refactor that? Thanks in advance!
Kind regards, Roald