1

I have a few forms in my forms variable, which I took from my DB.

views.py:

def settings(request):

new_form = TrafficSourcesForm()
forms = [TrafficSourcesForm(instance=x) for x in TrafficSources.objects.all()]

return render(request, 'mainpage/dashboard.html', {'new_form': new_form, 'forms': forms, 'error': error})

MY HTML:

 <h3>{{ error }}</h3>
        {% for form in forms %}
            <form method="POST" id="{{form.name.name}}">{% csrf_token %}</form>
        {% endfor %}
        <form method="POST" id="new-form"> {% csrf_token %}</form>
{% for form in forms %}
            <tr>
                <td>{{ form.name }}</td>
                <td>{{ form.token }}</td>
                <td><button class="btn btn-lg btn-success w-100">Save</button></td>

            </tr>
        {% endfor %}
<tr>
                <td><input class="form-control" placeholder="Name" form="new-form"></td>
                <td><input class="form-control" placeholder="API-token" form="new-form"></td>
                <td><button class="btn btn-lg btn-success w-100" form="new-form">Add</button></td>
            </tr>

I am making a kind of editable grid and using a table for my layout ( so I cannot put a form direct to a row). So I am making the forms separately with the new HTML 5 form tag. But I cannot take out the name(HTML attr on my inputs) which == the name field in the DB. So I could make different forms for every single row in my database. Can you help me? I was thinking about setting the id of the form from my forms object but it makes the same forms for every row.

mrdeath4
  • 161
  • 2
  • 13

0 Answers0