#12486: Accessing dict values via a value of a variable as hash
-----------------------------+----------------------------------------------
 Reporter:  uggsrock         |       Owner:  nobody    
   Status:  new              |   Milestone:            
Component:  Template system  |     Version:  1.1       
 Keywords:                   |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 In the current release (and previous releases also) there is no way to
 access the value of a dict or other struct with the value of a variable as
 the hash. For example if you want to have more than one struct you want to
 iterate over and get a key-value-based table with the data of other
 structs in it, you either have to do it manually inside the normal python
 code or with very ugly filters.
 [[BR]][[BR]]
 Here is a simple example i mentioned before:
 (we have dictionary1 and dictionary2 with the same size and keys)
 {{{
 {% for key,value in dictionary1.items %}
 <li>{{key}}: {{value}}, {{dictionary2.key}}</li>
 {% endfor %}
 }}}
 [[BR]]
 This wouldn't work because it would search for dictionary2.key or
 dictionary[ "key" ] (so key is the string "key", not a variable)
 [[BR]]But to get example working you would need it to call dictionary[ key
 ] whereas the key is a variable and its value would be used as a hash.
 Most solution with filters look this way:

 {{{
 @register.filter
 def hash(h, key):
     return h[key]
 }}}
 (took this one from [http://push.cx/2007/django-template-tag-for-
 dictionary-access]

 As you see, there is just this ugly (and by the way also slow) way through
 filters but no real one the template engine should provide itself.
 Therefore i would suggest to take something like "dict[ var ]" or "dict[
 inner_dict[ var ] ]" as the shortcut for the template engine to provide
 this usefull feature.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12486>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to