Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

drf default pagination

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 100
}
Comment

how to use drf pagination directly

from rest_framework.views import APIView
from rest_framework.pagination import PageNumberPagination

class ProductList(APIView, PageNumberPagination):
    # number of items per page by default
    page_size = 1000
    # max number of items per page
    max_page_size = 1000

    def get_queryset(self):
        product_sync_ts = self.request.GET.get('product_sync_ts', None)
        if product_sync_ts:
            products = GrProduct.objects.filter(update_ts__gt=product_sync_ts)
            return self.paginate_queryset(products)

        raise APIException400(request, {'details': "Bad Request"})

    def get(self, request):
        products = self.get_queryset()
        serializer = SyncedProductSerializer(instance={'products': products})
        return self.get_paginated_response(serializer.data)
Comment

PREVIOUS NEXT
Code Example
Python :: datetime year python 
Python :: python dictionary to csv 
Python :: python django include another app url 
Python :: python tkinter askopenfile 
Python :: python append element to array 
Python :: how to find no of times a elements in list python 
Python :: map function using lambda in python 
Python :: sort dictionary 
Python :: compute eigenvalue python 
Python :: how to print in pyhton 
Python :: star operator python 
Python :: how to write multi line lambda in python 
Python :: get all files in directory python 
Python :: python selenium clear input 
Python :: invert a dictionary python 
Python :: import matplotlib 
Python :: python loop x times 
Python :: horizontal bar plot python 
Python :: python check if exe is running 
Python :: load and image and predict tensorflow 
Python :: how to do http requetss python 
Python :: python datetime no milliseconds 
Python :: python apply function to dictionary values 
Python :: python more order of columns 
Python :: python convert list of strings to list of integers 
Python :: completely uninstall python and all vritualenvs from mac 
Python :: python get position of character in string 
Python :: Concatenate Item in list to strings 
Python :: pip install django 
Python :: python index list enumerate 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =