Tuesday, November 13, 2012

Whats the point of having dicts in templates if one cannot access them by key?

Let me explain, I have a nested dictionary like:

agenda = {'3': {'2012-11-11': <MyObject>, '2012-11-14': <MyObject>, ...},
  '7': {'2012-11-9': <MyObject>, },
  '2': {'2012-10-28': <MyObject>},
  }

And I want to access it by specifying the two keys. I've red that i must access the dict like (where attribute is an attribute of <MyObject>:

{% for k, a_dict in agenda.items %}
  {{ k }}
  {% for k2, v in a_dict.items %}
    {{ k }}-{{ k2 }}-{{ v.attribute }}
  {% endfor %}
{% endfor %}

But, whats the point of using dicts if I have to access the values in whatever order the <Dict>.items() gives me the keys and values?

What if I need to access these values in a specified order? (for the outer dict AND the inner ones)

Is there a way to access a two-dimensional container IN AN PRE-SPECIFIED ORDER?

Thaks for any advise.

pablete

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/y5GJm9E1D4YJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate