2016-12-22 3 views
0

ich will, das die Förderung Zählung heraus filtern undWie Wörterbuch in django Vorlage verwendet

hier für diese bestimmte Zählung des service_type und Promotion-Code speichern ist meine Ansicht

promotions=Promotions.objects.filter(member=request.user) 
     dictt={} 
     for promotion in promotions: 
       c=customer_request.objects.filter(promotion=promotion) 
       e=c.count() 
       dictt[e]=e 
       for w in c: 
        coupon_code=Promotions.objects.get(pk=w.promotion_id) 
        dictt.update({e:{coupon_code.coupon_code,w.service_type}}) 
     sorted_dictt = sorted(dictt.items(), key=operator.itemgetter(0), reverse=True) 

und ich bin Anzeige dict auf html als

{% for a in sorted_dictt %} 
      <tr> 
       <td style="color:#f38619;"></td> 
       <td style="color:#f38619;">{{a.1}}</td> 
       <td style="color:#f38619;">{{a.0}}</td> 
       </tr> 
       {%endfor%} 

jetzt folgt ich erhalte Ergebnisse als:

here is my display

sollte Anzeige als

it should display as

, wie es zu tun?

+0

Verwendung a.1.0 und A.1.1 – dnit13

Antwort

0

Sie sollten Wörterbuch wie folgt verwenden:

{% for key, value in dict.items %} 
    {{key}}-{{value}} 
{% endfor %} 
1

Die folgende Zeile sieht falsch:

# Here, dictt[e] is a set that contains coupon_code.coupon_code and w.service_type 
dictt.update({e:{coupon_code.coupon_code,w.service_type}}) 

Stattdessen schreiben:

dictt.update({e: coupon_code.coupon_code}) 
Verwandte Themen