Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using django-pagination to paginate my object list. It is working flawlessly. I want to give a number to each object on the page and I am using {{forloop.counter}} for that, but the problem is it starts the object count from 1 on each page. I wanted to display the actual object count.

Say if I am paginating 10 objects per page, then I want to object number as 11 for the first object on page 2. I tried writing a template filter for this, but somehow I am not able to send both request.get.page and {{forloop.counter}} to my filter function. I am unable to do it that way.

Any help for direction will be appreciated.

like image 633
Sachin Avatar asked Feb 21 '12 07:02

Sachin


1 Answers

You can use the add template tag to add the current count from the paginator to the forloop

{{ forloop.counter|add:paginator.page.start_index }}
like image 93
Timmy O'Mahony Avatar answered Oct 03 '22 08:10

Timmy O'Mahony