0

I have this array structure payment_list['seller']['order'] that contains an Order object and payment_list['seller']['orders_detail'] that contains a list of OrderDetail objects.

In views.py no problem to access to the elements, but in template I am capable to access only to the first element, and I need to access to Order object and to the OrderDetail list.

In views.py - NO PROBLEM

for order in orders:
    payment_list[order.seller] = {}
    payment_list[order.seller]['order'] = order
    payment_list[order.seller]['orders_detail'] = []

    orders_detail = OrderDetail.objects.filter(order=order)
    for od in orders_detail:
        payment_list[order.seller]['orders_detail'].append(od)

for pa in payment_list:
    print pa
    print payment_list[pa]
    print payment_list[pa]['order']
    for od in payment_list[pa]['orders_detail']:
        print od

In template.html - PROBLEM Impossible to access to the elements

1 way:

{% for pa, value_list in payment_list.items %}
    {{ pa }}<br> OK
    {% for value in value_list %}
        {% if value == 'order' %}
            ORDER:{{ value }}<br>
        {% endif %}
        {% if value == 'orders_detail' %}
            DETAIL:{{ value }}<br>
        {% endif %}
    {% endfor %}
{% endfor %}

2 way:

{% for pa in payment_list %}
    seller:{{ pa }}<br> OK
    order:{{ payment_list.pa }} It doesn't show anything
{% endfor %}

I am sure it is a little thing, I forgot something? Is the sintaxis bad?

Thank you!

  • checkout http://stackoverflow.com/questions/1275735/how-to-access-dictionary-element-in-django-template and http://stackoverflow.com/questions/2894365/use-variable-as-dictionary-key-in-django-template – JimmyYe Oct 05 '15 at 23:22
  • Thank you @JimmyYe. Now I can access it! – Juan Diego Gonzalez Oct 06 '15 at 09:09
  • I don't think these links are directly relevant though. This question is about accessing multi-dimensional lists, while those links are about simulating dictionaries. – Roozbehan May 27 '17 at 00:10

0 Answers0