All Projects → photocrowd → django-cursor-pagination

photocrowd / django-cursor-pagination

Licence: BSD-3-Clause license
Cursor-based pagination for Django

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to django-cursor-pagination

Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+195.24%)
Mutual labels:  pagination
QueryMovies
This repository shows a Android project with Clean Architecture, Functional Reactive Programming and MVP+Dagger
Stars: ✭ 16 (-87.3%)
Mutual labels:  pagination
pagination
Пример создания пагинации в Vue.js
Stars: ✭ 31 (-75.4%)
Mutual labels:  pagination
kaminari-sinatra
Kaminari Sinatra adapter
Stars: ✭ 26 (-79.37%)
Mutual labels:  pagination
graphql-compose-pagination
Plugin for TypeComposer (graphql-compose), that adds `pagination` resolver.
Stars: ✭ 29 (-76.98%)
Mutual labels:  pagination
paginathing
a jQuery plugin to paginate your DOM easily.
Stars: ✭ 23 (-81.75%)
Mutual labels:  pagination
pagination
Aplus Framework Pagination Library
Stars: ✭ 167 (+32.54%)
Mutual labels:  pagination
express-mquery
Expose mongoose query API through HTTP request.
Stars: ✭ 37 (-70.63%)
Mutual labels:  pagination
discord-paginationembed
A pagination utility for MessageEmbed in Discord.JS
Stars: ✭ 93 (-26.19%)
Mutual labels:  pagination
AdvancedList-SwiftUI
MOVED to https://github.com/crelies/AdvancedList | Advanced list with empty, error and loading state implemented with SwiftUI
Stars: ✭ 41 (-67.46%)
Mutual labels:  pagination
RxPagination
Implement pagination in just few lines with RxPagination
Stars: ✭ 20 (-84.13%)
Mutual labels:  pagination
SwiftyUIScrollView
A custom ScrollView wrapper that comes with Pagination and Page Control.
Stars: ✭ 18 (-85.71%)
Mutual labels:  pagination
lampager-laravel
Rapid pagination for Laravel
Stars: ✭ 71 (-43.65%)
Mutual labels:  pagination
go-paginate
Cursor-based go paginator
Stars: ✭ 48 (-61.9%)
Mutual labels:  pagination
Pagination
a paging widget based on Qt
Stars: ✭ 22 (-82.54%)
Mutual labels:  pagination
developer-guides
Developer Guides
Stars: ✭ 25 (-80.16%)
Mutual labels:  pagination
jekyll-pagination
Better pagination for Jekyll.
Stars: ✭ 19 (-84.92%)
Mutual labels:  pagination
InfiniteScroll
You can do a Endless scroll in ListView or RecyclerView with simple steps, with a listener for do request to your web service.
Stars: ✭ 28 (-77.78%)
Mutual labels:  pagination
simple-datagridview-paging
A simple UserControl that shows the data-table and paging automatically with .Net Framework
Stars: ✭ 23 (-81.75%)
Mutual labels:  pagination
paginater
Package paginater is a helper module for custom pagination calculation.
Stars: ✭ 45 (-64.29%)
Mutual labels:  pagination

Django cursor pagination Build Status

A cursor based pagination system for Django. Instead of refering to specific pages by number, we give every item in the queryset a cursor based on its ordering values. We then ask for subsequent records by asking for records after the cursor of the last item we currently have. Similarly we can ask for records before the cursor of the first item to navigate back through the list.

This approach has two major advantages over traditional pagination. Firstly, it ensures that when new data is written into the table, records cannot be moved onto the next page. Secondly, it is much faster to query against the database as we are not using very large offset values.

There are some significant drawbacks over "traditional" pagination. The data must be ordered by some database field(s) which are unique across all records. A typical use case would be ordering by a creation timestamp and an id. It is also more difficult to get the range of possible pages for the data.

The inspiration for this project is largely taken from this post by David Cramer, and the connection spec for Relay GraphQL. Much of the implementation is inspired by Django rest framework's Cursor pagination.. The main difference between the Disqus approach and the one used here is that we require the ordering to be totally determinate instead of using offsets.

Installation

pip install django-cursor-pagination

Usage

from cursor_pagination import CursorPaginator

from myapp.models import Post


def posts_api(request, after=None):
    qs = Post.objects.all()
    page_size = 10
    paginator = CursorPaginator(qs, ordering=('-created', '-id'))
    page = paginator.page(first=page_size, after=after)
    data = {
        'objects': [serialize_page(p) for p in page],
        'has_next_page': page.has_next,
        'last_cursor': paginator.cursor(page[-1])
    }
    return data

Reverse pagination can be achieved by using the last and before arguments to paginator.page.

Caveats

  • The ordering specified must uniquely identify the object.
  • If a cursor is given and it does not refer to a valid object, the values of has_previous (for after) or has_next (for before) will always return True.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].