Skip to main content

Infinite pagination for Django.

Project description

This is a very simple helper for Django 1.4 that does one thing: efficiently paginates large object collections on systems where using standard Django Paginator is impractical because of significant count(*) query overhead (i.e. PostgreSQL).

Under the hood it uses a single query to retrieve objects for the current page and check for availability of a successive page.

The InfinitePaginator is a replacement for Django django.core.paginator.Paginator.

Quick Start

Include django-infinite-pagination in your requirements file (or pip install django-infinite-pagination) and add infinite_pagination to INSTALLED APPS.

Then set the paginator_class attribute of your ListView-based view to InfinitePaginator and specify paginate_by attribute:

class ArticleListView(ListView):
    model = Article
    paginate_by = 10
    paginator_class = InfinitePaginator

To display pagination links in a template load the infinite_pagination template tags and put {% paginate %} in the place you would like the pagination links to show up:

{% load infinite_pagination %}

{% for object in object_list %}
    {{ object }}
{% endfor %}

{% paginate %}

A generic pagination/infinite_pagination.html template that works well with Twitter Bootstrap stylesheet is provided by this application. Adjust it to your requirements.

Paginating in Templates

Sometimes application views cannot be modified and the pagination can only be done at the template level. The autopaginate template tag is provided as a last resort of applying pagination to object lists inside templates:

{% load infinite_pagination %}

{% autopaginate object_list per_page=10 as paginated_list %}

{% for object in paginated_list %}
    {{ object }}
{% endfor %}

{% paginate %}

The autopaginate tag takes a queryset and a number of items per page as input and returns a page slice for displaying in a template. Current page number is retrieved from template context or page request GET params. It can also be specified as an optional tag param:

{% autopaginate object_list per_page=10 page=2 as paginated_list %}

The tag also sets paginator and page_obj template context variables for the paginate tag that uses them to render navigation links.

License

django-infinite-pagination is released under the BSD license.

Other Resources

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-infinite-pagination-mega-1.1.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file django-infinite-pagination-mega-1.1.tar.gz.

File metadata

File hashes

Hashes for django-infinite-pagination-mega-1.1.tar.gz
Algorithm Hash digest
SHA256 0b28fb0a8da4224616c062cc065fe96b3d58e5ff68008f8cdae092e8232cb05d
MD5 4615205ef3f8fc43e0eddc0ba40f0d98
BLAKE2b-256 2f1675dcab3b5599ed4c11b05cf58774b0f3de7850a9a37d586fddf2e9555337

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page