I have the following template code,presently i m getting for loop counter as label for my formset. How can i get elements of array ‘month’ (eg month.counter, where counter is loop) as my label?? I tried {{month.forloop.counter}} but that didnt worked
<html>
<head>
<title>Actuals</title>
</head>
<body>
<h1>Actuals Data</h1>
<h2>Your Account Number is : {{ Account_Number }}</h2>
<h2>You Chose {{ Year }} {{month}} as period.</h2>
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }}below.</p>
{% endif %}
<form action="." >
{{ formset.management_form }}
<table>
{% for form in formset %}
{{form.id}}
<div class="field">
{{ form.Value.errors }}
<label for="id_Value">{{months}}.{{forloop.counter}}</label>
{{ form.Value }}
</div>
{% endfor %}
</table>
</form>
</body>
</html>
You can do this using custom templatetags. Sample code is given below:
add following to /{app_name}/templatetags/app_tags.py
put following in your template
View this link, some person has also tried different methods to do this; although none of them worked. 😉