Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 %}


    {% for page in paging.pages %}
  • {{ page.number }}

  • {% 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 %}


    {% if paging.first %}
  • First - {{ paging.first.number }}

  • {% endif %}

    {% if paging.prev %}

  • Previous - {{ paging.prev.number }}

  • {% endif %}

    {% for page in paging.pages %}

  • {{ page.number }}

  • {% endfor %}

    {% if paging.next %}

  • Next - {{ paging.next.number }}

  • {% endif %}

    {% if paging.last %}

  • Last - {{ paging.last.number }}

  • {% 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' %}


{% endpaginate %}