How to pass value to a modelform_factory function from djnago templates
In my template, I have a loop to display each row in a table, each row has a couple of input fields from the formset function I created. I'm facing an issue where I want to pass an id for each row I'm looping in so that I can control the data inserted in my database, but the problem is how can I detect the id of each row I'm in, to insert each row separately?
{% for products in products_info %}
<tr>
<td>{{issuance_formset.checked}}</td>
<td><a href="#" class="open-modal" data-url="{% url 'shop:item_modal' products.id %}">{{products.item.name}}</a></td>
<td>{{issuance_formset.factory}}</td>
<tr>
{% endfor %}
what I want is to pass the products.id for each row from each loop iteration along with the form request. Is there a way to do that?
Can you use forloop.counter?
{% for products in products_info %}
<tr id="row_{{forloop.counter}}">
<td>{{issuance_formset.checked}}</td>
<td><a href="#" class="open-modal" data-url="{% url 'shop:item_modal' products.id %}">{{products.item.name}}</a></td>
<td>{{issuance_formset.factory}}</td>
<tr>
{% endfor %}
There's a few variables set by the for loop along this line. See the docs for more!