Thank you all. I have fix my issue icons sorteddict from the Python
collections.

Juan Pablo Tamayo H
Sent from my Android phone
On Nov 14, 2012 11:38 AM, "Bill Freeman" <ke1g...@gmail.com> wrote:

>
>
> On Tue, Nov 13, 2012 at 11:40 PM, Juan Pablo Tamayo <jtama...@gmail.com>wrote:
>
>> 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
>>
>
> I believe that if the keys were valid python identifiers you could access
> them using dot notation.  E.g.; if a_dict is dict(a=dict(aa='foo')), then
> in the template you could say {{ a_dict.a.aa }}.  This may work with the
> simple numbers, but with the keys containing minuses there may be
> problems.  You could try quoting them.
>
> If none of that stuff is going to work for you, you aught to be able to
> write a simple template filter that filters the dict, and takes the key as
> a quoted fight hand argument.  You then cascade this for nested
> dictionaries.
>
> But if it were me, I'd probably see if I couldn't do it in the view,
> producing lists or tuples with the stuff in the order you need them.
>
> Bill
>
> --
> 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.
>

-- 
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.

Reply via email to