How to show the correct object numbers (counter) when using django-pagination

I'm using this template tag to output the order numbers of an object list in a for loop:

{% for myobj in myobjlist %}
{{ forloop.counter }}
...
{% endfor %}

But if I use pagination, the number will always start from 1 in a new page. Here is the trick to show the correct number: add to the counter (use zero index instead, counter0) the object index:

{{ forloop.counter0|add:myobjlist.start_index }}


Neat!

Comments