Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/livioribeiro/django-smart-pagination
Smart pagination links for Django
https://github.com/livioribeiro/django-smart-pagination
Last synced: 12 days ago
JSON representation
Smart pagination links for Django
- Host: GitHub
- URL: https://github.com/livioribeiro/django-smart-pagination
- Owner: livioribeiro
- License: bsd-3-clause
- Created: 2015-09-29T18:13:14.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-12T11:51:39.000Z (about 9 years ago)
- Last Synced: 2024-11-23T18:40:28.004Z (30 days ago)
- Language: Python
- Size: 199 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=======================
django-smart-pagination
=======================Generate pagination links for Django
Instead of displaying links to all the pages at once, django-smart-pagination calculates a limited subset of them.
Works with Django Templates and Jinja2.
-----
Usage
-----First add ``smart_pagination`` to your installed apps:
.. code:: python
INSTALLED_APPS = [
'smart_pagination'
]Use a pagination block passing the ``Page`` object, the number of links (literal of variable)
and the name to associate the ``smart_pagination.Paginator`` object... code:: django
{% load pagination_tags %}
{% paginate page_obj num_links paging %}
- {{ page.number }}
{% for page in paging.pages %}
{% endfor %}
{% endpaginate %}
The ``Paginator`` object contains the following properties:
===== =================================================================
first First ``Page``. Will be ``None`` if it is already the first page.
prev Previous ``Page``. Will be ``None`` if there is no previous page.
pages List of pages.
next Next ``Page``. Will be ``None`` if there is no next page.
last Last ``Page``. Will be ``None`` if it is already the last page.
===== =================================================================
.. code:: django
{% load pagination_tags %}
{% paginate page_obj num_links paging %}
- First - {{ paging.first.number }}
- Previous - {{ paging.prev.number }}
- {{ page.number }}
- Next - {{ paging.next.number }}
- Last - {{ paging.last.number }}
{% if paging.first %}
{% endif %}
{% if paging.prev %}
{% endif %}
{% for page in paging.pages %}
{% endfor %}
{% if paging.next %}
{% endif %}
{% if paging.last %}
{% endif %}
{% endpaginate %}
If you are sending the page_kwarg as a query parameter, you can optionally pass a fourth argument with the name
of the page_kwarg and the ``Paginator`` will provide the query string without the page_kwarg:
.. code:: django
{% load pagination_tags %}
{% paginate page_obj num_links paging 'page' %}
- {{ page.number }}
{% for page in paging.pages %}
{% endfor %}
{% endpaginate %}