Giter Club home page Giter Club logo

drf-timestamp-pagination's Introduction

DRF Timestamp Pagination

Pagination serializer for Django Rest Framework that uses Timestamp Paginator

Why we needed this?

Classical pagination (?page=2) doesn't work properly with actively updated list pages.

Example:

Imagine a web page where people upload their pet's pictures.

  • Anyone can upload a picture anytime and it will be listed.
  • The newest picture appears at the top of the page.
  • When the list will be complete, the users will go to the second page (by a link or infinite loader).

This will work fine.

However, if during this time period, a new image will be uploaded, the last image of the first page will become the first item of the second page.

In order to prevent this problem, there are many alternative ways that can be used. One of the best alternatives is to use timestamps instead of page numbers.

This paginator makes the pagination by the timestamps of the items.

Installation

pip install drf-timestamp-pagination

Usage

from django_timestamp_paginator import TimestampPaginator
from drf_timestamp_pagination import TimestampPaginationSerializer, TimestampPaginationMixin


class CommentsView(TimestampPaginationMixin, ListCreateAPIView):  # Add mixin to left-hand side
	pagination_serializer_class = TimestampPaginationSerializer
	paginator_class = TimestampPaginator
	timestamp_field = 'timestamp'

### Rest of the class

Done.

paginate_by, paginate_by_param, max_paginate_by also applies to TimestampPaginationSerializer.

Sample View Response

{
    "next": "https://api.example.com/feed/?next=1425028897.60",
    "next_max_timestamp" : 1425028897.60,
    "results": [
        { result set }
    ]
}

drf-timestamp-pagination's People

Contributors

umutbozkurt avatar yigitguler avatar

Stargazers

 avatar Emrah YILDIRIM avatar Christoph Klein avatar Bogdan Petrea avatar Hammad avatar Heval Azizoğlu avatar Nikolaus Schlemm avatar Angus H. avatar Jordan Baltes avatar pyzen avatar Alessio Di Stasio avatar Jonathan Barratt avatar Adam Cook avatar Matteo Scotuzzi avatar Julio Carlos Menendez avatar  avatar Serkan (E.) Sökmen avatar Emre Yılmaz avatar  avatar Taylan Pince avatar  avatar

Watchers

Emre Yılmaz avatar Mark Reist avatar aybars badur avatar Tuna Vargi avatar James Cloos avatar Kaan Eryilmaz avatar Marco avatar Oktay avatar  avatar Mert Akkaya avatar Can Goktas avatar  avatar  avatar Mucahit Tutuncu avatar Ozan Dogrultan avatar  avatar Mert Ahmet Güneş avatar Ömer Aslan avatar Hacer Nur Yanaral avatar Burak Balta avatar Cem Arguvanlı avatar Göktuğ Berk Ulu avatar Ömer Kırnap avatar  avatar Tolga Can Ünal avatar Cagla Cetin avatar Cafer Ömürden Cengiz avatar  avatar Goksel Coban avatar Batuhan Karasakal avatar  avatar  avatar Kadir Can Çetin avatar

drf-timestamp-pagination's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.