#3371: Filter to get dict's value by key name (for the purpose of enabling
variable lookups in the template)
-------------------------------------+-------------------------------------
     Reporter:  Alex Dedul           |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Template system      |                  Version:  master
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:  template filter      |             Triage Stage:
  dict key                           |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by anonymous):

 I pass dict
 {{{
 AddonMap = {'menu': '1', 'opening_hour': '2', 'books': '3', 'Doctors':
 '4'}
 }}}
  and
 {{{
 addon_list = [{u'menu': [{u'price': 50, u'name': u'Momo', u'price_level':
 u'cheap'}, {u'price': 510, u'name': u'potato', u'price_level':
 u'expensive'}, {u'price': 100, u'name': u'Chowmein', u'price_level':
 u'expensive'}]}, {u'opening_hour': [{u'close': 17, u'open': 9, u'day': 0},
 {u'close': 17, u'open': 9, u'day': 1}, {u'close': 16, u'open': 8, u'day':
 2}]}]
 }}}
 Now I need put href of id based on key (menu) of dict. How can I achieve
 that. Please Help me.

 {{{

 {% if addon_list %}

     {% for addon_name in addon_list %}
         {% for key, values in addon_name.iteritems %}
             <table>
             <tr>
                 <td>
                     <h2>{{ key }}</h2>{# title- menu #}
                 </td>


                 <td><h5><a href="{% url 'addon:update_addon' spot_id '''
 <I need value of key variable here. for key == menu I need 1>'''''''
 %}">update</a></h5></td>
             </tr>


             <tr>
             </tr>

             {% for value in values %}
                 {% for k,v in value.iteritems %}
                     <tr>
                         <td>{{ k }}</td>
                         <td>{{ v }}</td>
                         {#                        <td><h5><a href="{% url
 'addon:update_addon_item' spot_id addon_id item_id %}" </h5></td>#}
                     </tr>
                 {% endfor %}
             {% endfor %}
         {% endfor %}
     {% endfor %}
 </table>
 {% endif %}
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/3371#comment:21>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.ba7df7687cd10fa73c2eb7185bb401e9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to