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

paginating drf

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 2,
}
Comment

PREVIOUS NEXT
Code Example
Python :: python variable declare 
Python :: drop-trailing-zeros-from-decimal python 
Python :: python sets 
Python :: socketserver python 
Python :: how to add a value to a list in python 
Python :: factors for negative number python 
Python :: subset a list python 
Python :: install local package python 
Python :: pandas dataframe.to_dict 
Python :: tweepy auth 
Python :: python index of string 
Python :: python list all but first 
Python :: reverse python 
Python :: not equal to in django filter 
Python :: python test if list of dicts has key 
Python :: Read JSON files with automatic schema inference 
Python :: entropy formula pyhon 
Python :: how to merge rows in pandas dataframe 
Python :: Python NumPy repeat Function Example 
Python :: numpy declare arraylength 
Python :: python example 
Python :: sending email with django 
Python :: math domain error python 
Python :: generate rsa key python 
Python :: face detection code 
Python :: mse python 
Python :: python create dictionary from csv 
Python :: save model history keras 
Python :: custom attribute selenium 
Python :: dataframe to pandas 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =