{{forloop.counter | add: forloop.parentcounter.counter}}, , , python, django.,
add-
class make_incrementor(object):
count = 0
def __init__(self, start):
self.count = start
def inc(self, jump=1):
self.count += jump
return self.count
def res(self):
self.count = 0
return self.count
def EditSchemeDefinition(request, scheme_id):
iterator_subtopic = make_incrementor(0)
scheme_recs = scheme.objects.get(id=scheme_id)
view_val = {
'iterator_subtopic': iterator_subtopic,
"scheme_recs": scheme_recs,
}
return render(request, "edit.html", view_val)
django "iterator_subtopic" , :
<td id="subTopic" class="subTopic">
<p hidden value="{{ iterator_subtopic.res }}"></p>
{% for strand in scheme_recs.stand_ids.all %}
{{ iterator_subtopic.res }}
{% for sub_strand in strand.sub_strand_ids.all %}
{% for topic in sub_strand.topic_ids.all %}
{% for subtopic in topic.sub_topic_ids.all %}
<input id="subTopic{{ iterator_subtopic.inc }}" class="len"
value="{{ subtopic.name }}">
<br>
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
, , , .
source
share