How to show continuous serial number in pagination using django

I have a blog list layout. Now i am using {{forloop.counter}} in my template to generate serial numbers and it is working perfectly. Page 1 shows 1 - 20 serial number, then page 2 shows again 1 - 20 serial numbers. but i want to show serial number from 21 - 40 in page 2 and so on.. instead of 1 - 20 again and again in every page. How to do this using django

Reason: Your serial number generated from {{forloop.counter}} based on current page data.

Probable Solution:

  1. You can use {{obj.id}} so that DB primary key will be displayed as a serial number.
  2. You can make another field in the database to maintain a serial number based on your requirements.
  3. You can write Django custom template tags to calculate the serial number from {{forloop.counter}} or based on your context.

Best of luck :)

Back to Top