[Answered ]-Django field name conflicts on save

2👍

Use prefix in the form, like this:

context['farm'] = FarmForm(prefix="farm_form")
context['appuser'] = FarmUserCreateForm(prefix='farm_user_create')

0👍

Check the name attribute in the rendered forms, in particular those for the {{ appuser.name }} and {{ farm.name }} input elements.

I guess they are the same, because I don’t think there is be namespacing going on inside the rendered template. Thus, there’ll be two <input name="name" ...> elements, and upon POST, one will overwrite the other.

Hence when you’re creating the bound forms inside the post(...) method, you fill both forms with the same name. You can verify the latter by printing the value of self.request.POST when running the development server: you should only see one name key.

Leave a comment