On Tue, 2009-03-10 at 10:04 -0700, johan.uhIe wrote: > I have the following hierarchical data structure making use of the > datetime-object, dictionarys, arrays and tuples all at once. > > { datetime : > { (datetime, datetime) : > [<object1>,<object2>] > } > } > > So a dictionary, holding datetime objects as keys and another > dictionary as value. The second dictionary has tuples consisting of > two datetime objects as keys and an array as value. > > Reason for this complicated structure is the supposed easy handling in > the template with three for-loops to iterate over the two dictionarys > and the array. The first datetime object holds a specific day whereas > the tuple is holding a time period. The array holds the objects > related to the time period. > > So I used this in a template as following: > > {% for key,value in dictionary.items %} > <h2>{{key|date:"Y-m-d"}}</h2> > {% for key,value in value %} > <h3>{{ key.0|date:"H.i" }} - {{ key.1|date:"H.i" }}</h3> > {{ value }} // Array handling > {% endfor %} > {% endfor %} > > But the problem is, that inside the second for loop the key/value > assignment does not work properly. I expected the tuple to be in key, > so I can access it via key.0 and key.1 and the array to be in value. > What actually happens is, that my first datetime object from the tupel > is in key and the second datetime is in value but the array is nowhere > to be found.
The "value" in the outer loop is a dictionary. So in the inner loop you need to loop over value.items. "foo in some_dictionary" loops over the keys of the dictionary and, since that's a tuple, the two elements of the tuple are being assigned to the two variables you're providing. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---