FAQ
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 }}
{% endif %}
{{ 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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Y-SyKhGnnLIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedMay 7, '12 at 3:20p
activeMay 7, '12 at 3:20p
posts1
users1
websitedjangoproject.com

1 user in discussion

Roald: 1 post

People

Translate

site design / logo © 2022 Grokbase