I have a ChoiceField in a bound form, whose choices are:
[('all', 'All users'), ('group', 'Selected groups'), ('none', 'None')]
In the template, I have no problem accessing its bound value (the actual value to be stored; the first element of each tuple) and the choices. With these pieces of info in hands, I know I should be able to access the display values, or the second element of each tuple. But how can I do that in the template? Thanks.
foo = ['a', {'b': 'c'}]
the way you would access that in a template isfoo.1.b
i.e. you can access something using square brackets with the dot notation that Django templates have. You cannot however use a variable to specify the index without some kind of custom filter like{% with foo|index:my_variable as this_choice %}this_choice.b{% endwith %}
which instead becomes incredibly messy so you are better of with a more specialised filter or to prepare your data in the view. Since this question is quite old, I'm sure you are well aware of that by now. – Pandich