djangosnippets.org: Latest snippets tagged with 'increment'https://djangosnippets.org/tags/increment/2011-12-01T08:04:35.810802-06:00Django Incremental Counter Tag
2011-12-01T08:04:35.810802-06:00gwrtheyrnhttps://djangosnippets.org/snippets/2619/<p>Counter tag. Can be used to output and increment a counter.</p>
<p>For usage, see docstring in the code.</p>
<p>This is the first complete tag that I've implemented, I hope that there are no bugs and that it's thread safe.</p>
Freely redistributablecounter templatetag
2009-11-12T09:42:00.508900-06:00bcurtuhttps://djangosnippets.org/snippets/1794/<p>The counter initializes the variable to 0, and next it increments one by one:</p>
<pre><code>{% load counter_tag %}
{% for pet in pets %}
{% if pet.is_cat %}
{% counter cats %}
{% else %}
{% counter dogs %}
{% endif %}
{% endfor %}
# cats: {{cats}}
# dogs: …</code></pre>
Freely redistributable