I want to use forms.ModelForm, however, I’m using the same form multiple times in the template.
e.g.
...
{{ form.as_p }}
{{ form.as_p }}
{{...
...
Therefore, the names and ids of the forms are all the same. So how can I still use ModelForm but change the ids and names of the inputs?
You could add an name/id to each form using a handful of different techniques, though you probably want to use a
formset.https://docs.djangoproject.com/en/dev/topics/forms/formsets/
These can be confusing initially if you’ve been looking at forms, but so long as you understand that it’s another layer of abstraction and you need to take care of which
ModelForminstance you are working with.Specifically you may want to use
django.forms.models.modelform_factory.https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#model-formsets
Usage is really easy, but if you want to do anything interesting with the forms it can be more difficult: