iterate choices and get_FOO_display
jucajuca opened this issue · 2 comments
jucajuca commented
Hello,
How can I iterate at the same time the values and the display strings for a choice?
I tried this and some other options, but I can't figure it out.
{% for choice in multifield %}
{{choice }} -- {{ choice.get_display }}.
{% endfor %}
any help is appreciated. thanks!
jucajuca commented
I had to do it like this:
tags.py
@register.filter
def get_item(dictionary, key):
return the dictionary.get(key)
{% for key in multifield %}
{{ key }} -- {{ multifield.choices | get_item:key }}.
{% endfor %}
but it would be better to loop through the selected choices as usual with the usual:
{% for key, value in multifield %}
{{ key }} -- {{ value }}.
{% endfor %}