Possible Duplicate:
Python-Django: ifchanged template tag
This is my present code:
{% for eachSc in DBShots1 %}
<tr>
{% ifchanged eachSc.laEmpNum %}
<td> </td><td> </td>
<td bgcolor="#FFFACD" width="1%">Tot={{ result }}</td>
{% endifchanged %}
</tr>
<td bgcolor="#FFFACD" width="1%">{{ forloop.counter }} </td>
<td bgcolor="#CCFACD" width="1%">{{ eachSc.sName }}</td>
<td bgcolor="#CCF0F5" width="1%">{{ eachSc.duration }}</td>
<td bgcolor="#CCFACD" width="1%">{{ eachSc.frames }}</td>
<td bgcolor="#CCFACD" width="5%">{{ GetEmpDept }} - {{ eachSc.laEmpNum }}</td>
{% endfor %}
From the above code it displays like below:
Tot=[(u'1046', 5.5), (u'8008', 4.5), (u'8011', 1.3)]
1——-01——2.5————-60——allLayout – 1046
2——-02——2.0————-48——allLayout – 1046
3——-04——1.0————–0——allLayout – 1046
Tot=[(u'1046', 5.5), (u'8008', 4.5), (u'8011', 1.3)]
4——-03——2.3————-50——allLayout – 8008
5——-06——2.2————-0——-allLayout – 8008
Tot=[(u'1046', 5.5), (u'8008', 4.5), (u'8011', 1.3)]
6——-05——1.3————-0——-allLayout – 8011
But my output should be display like below:
if empID change(1046,8008,8011) then
{{ forloop.counter }} should start with one(1) and {{ result }} should display first element((1046,5.5) for first ID(1046)
second(8008′,4.5) element for second ID(8008) and so on:
1——-01——2.5————-60——allLayout – 1046
2——-02——2.0————-48——allLayout – 1046
3——-04——1.0————-0——-allLayout – 1046
Tot=(1046,5.5)
1——-03——2.3————-50——allLayout – 8008
2——-06——2.2————-0——-allLayout – 8008
Tot=(8008', 4.5)
1——-05——1.3————-0——-allLayout – 8011
Tot=(8011', 1.3)
You don’t need to use ifchanged here.
You should index your
resultwithforloop.counter0but is not possible with django templating system.You can write a custom tag to do this or change your view adding your result to the object context.