I need to generate unique id in each loop instead of ````city-selected```
{% for form in formset.forms %}
<tr>
{% for field in form %}
<td class="input_td{% if field.errors %} error_td{% endif %}">
<select name="city-select" id="city-select"></select>
</td>
{% endfor %}
<td class="delete_formset_td"></td>
</tr>
{% endfor %}
How can I generate it here?
I need some thing like this for ids:
output:
city-1
city-2
city-3
...
You can use {{ forloop.counter }}
. It gives you the loop iteration as a number.
See here.
{% for field in form %}
<!-- your html -->
city-{{ forloop.counter }}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With