Changes between Initial Version and Version 1 of Ticket #12486
- Timestamp:
- Jan 2, 2010, 4:23:50 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #12486
- Property Resolution → wontfix
- Property Status new → closed
- Property Summary Accessing dict values via a value of a variable as hash → Accessing dict values via a value of a variable as key
-
Ticket #12486 – Description
initial v1 1 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.2 [[BR]][[BR]] 1 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 key. 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. 2 3 3 Here is a simple example i mentioned before: 4 4 (we have dictionary1 and dictionary2 with the same size and keys) … … 10 10 [[BR]] 11 11 This wouldn't work because it would search for dictionary2.key or dictionary[ "key" ] (so key is the string "key", not a variable) 12 [[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.12 [[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 key. 13 13 Most solution with filters look this way: 14 14 15 15 {{{ 16 16 @register.filter 17 def hash(h, key):18 return h[key]17 def lookup(d, key): 18 return d[key] 19 19 }}} 20 20 (took this one from [http://push.cx/2007/django-template-tag-for-dictionary-access]