[Fixed]-Two django ModelForms on the same page, same model, without Formset

1👍

The id of the DOM element is not important in this case. The important property is the name of the input element.

It sounds like you need to use the prefix attribute of the ModelForm. Check https://docs.djangoproject.com/en/2.0/ref/forms/api/#prefixes-for-forms.

Initialise the form with

form1 = RegistrationForm(request.POST or None, instance=user_reg1, prefix='user1')
form2 = RegistrationForm(request.POST or None, instance=user_reg2, prefix='user2')

You’ll then end up with input element names prefixed with the value you gave for the prefix argument, which will prevent the namespace collision you are experiencing.

👤ChidG

Leave a comment