1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from django import template
from django.conf import settings
register = template.Library()
@register.filter
def adjust_for_pagination(value, page):
value, page = int(value), int(page)
adjusted_value = value + ((page - 1) * settings.RESULTS_PER_PAGE)
return adjusted_value
# And the template snippet:
{% for object in object_list %}
<div class="serial-no">
{% if is_paginated %}
{{ forloop.counter|adjust_for_pagination:page }}
{% else %}
{{ forloop.counter }}
{% endif %}
</div>
...
{% endfor %}
|
More like this
- Paginator Tag for 1.x by HM 4 years, 2 months ago
- Search results pagination by polarbear 6 years, 1 month ago
- Paginator Tag by insin 6 years, 2 months ago
- Pagination/Filtering Alphabetically by zain 4 years, 2 months ago
- Template tag to create a list from one or more variables and/or literals by davidchambers 2 years, 8 months ago
Comments
Can be achieved with:
#
And the Truth shall set you free.
Thanks for pointing that out. I'll have fun removing that code from my repo ;)
#