Access to index of list field in django template

Viewed 62

models.py

class Keys(models.Model):
    CHOICES     = (('a','a'),('b','b'),('c','c'),('d','d'))
    choice           =   MultiSelectField(choices=CHOICES,blank=True)

My template:

{% for k in m.choice %}
  {{????}}
{% endfor %}

How i can access to index of value in list fields? If user was selected a and c, Sample Output:

0
2
1 Answers

I'm using {{ forloop.counter }} which is counting the loop that you are in, starting from 1 to xx.

Related