[Answer]-Muliple instances of modelform

1👍

You have to use form’s prefix in the view like (just something unique for each form object):

def foo(request, ...):
    objs = Model.objects.filter(...)
    forms = []
    for i, obj in enumerate(objs):
        form = ModelForm(instance=obj, prefix=str(i))
        forms.append(form)
    ...

This will make sure each form has unique identifier, hence you will be able to submit a specific form.

And you can render the forms like usual in the template:

<form ...>
{% csrf_token %}
{% for form in forms %}
    {{ form }}
{% endfor %}
</form>

Leave a comment