Improving the return of a specific result

2

I think I'm unlearning the basics!

I have a result that returns only one element in the dictionary:

[{'quant': 236, 'district': 'Centro'}]

My context is:

context['Districts'] = d

As I do in the template I write something like

{{ Districts.district }} - {{ Districts.quant }}

instead of

{% for i in vehicleDistrict %}
    {{ i.dealership__district }} - {{ i.quant }}
{% endfor %}

Since the interaction is only one item?

    
asked by anonymous 07.06.2015 / 04:24

1 answer

2

In fact, it returns only one element in the list, so just pick up the first element (unique in this case) and move to the template.

view:

d = [{'quant': 236, 'district': 'Centro'}][0]

template:

{{ d.quant }} - {{ d.district }}

You can still use this feature directly in the template but I do not think it's a good practice:

{{ District.0.quant }}
    
07.06.2015 / 17:44