I wanted to make the following list into a dictionary:
lists.py
status_list = (
('c', 'cancelado'),
('elab', 'em elaboração'),
('p', 'pendente'),
('co', 'concluido'),
('a', 'aprovado')
)
So I did the following:
Views.py
class ProposalList(ListView):
template_name = 'core/proposal/proposal_list.html'
model = Proposal
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(ProposalList, self).get_context_data(**kwargs)
dct = {}
for i in status_list:
dct[i[0]] = i[1]
context['status'] = dct
return context
And it returns me a dictionary:
{'p': 'pendente', 'co': 'concluido', 'elab': 'em elaboração', 'a': 'aprovado', 'c': 'cancelado'}
Dai in the template I wanted to do:
<ul class="list-inline">
{% for item in status %}
<li name="{{ item }}">{{ get_item_display }}</li>
{% endfor %}
</ul>
Question : Why does not it work? In case, get_item_display does not return anything.