Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Django APIView Pagination

# stack overflow url: https://stackoverflow.com/questions/35830779/django-rest-framework-apiview-pagination

from rest_framework.pagination import LimitOffsetPagination

class EventNewsItems(APIView, LimitOffsetPagination):

    def get(self, request, pk, format=None):
        event = Event.objects.get(pk=pk)
        news = event.get_news_items().all()

        results = self.paginate_queryset(news, request, view=self)
        serializer = NewsItemSerializer(results, many=True)
        return self.get_paginated_response(serializer.data)
Comment

django pagination class based views

from django.core.paginator import Paginator
from django.shortcuts import render

from myapp.models import Contact

def listing(request):
    contact_list = Contact.objects.all()
    paginator = Paginator(contact_list, 25) # Show 25 contacts per page.

    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, 'list.html', {'page_obj': page_obj})
Comment

PREVIOUS NEXT
Code Example
Python :: python swap numbers 
Python :: histogram seaborn python 
Python :: python remove duplicates from list of dict 
Python :: RuntimeError: dictionary changed size during iteration 
Python :: tk is not defined python 3 
Python :: resize cmd using python 
Python :: time in regression expression python 
Python :: dataframe pandas empty 
Python :: convert pandas dataframe to numpy dataframe 
Python :: python how to draw a circle 
Python :: Python Tkinter RadioButton Widget 
Python :: how to access http page in pythion 
Python :: pydub play audio 
Python :: if string in list python 
Python :: run multiple test cases pytest 
Python :: python print function 
Python :: pandas correlation matrix between one column and all others 
Python :: pandas astype str still object 
Python :: absolute url 
Python :: get the invite url of server disc.py 
Python :: convert integer to binary in python 
Python :: python convert string to list of dictionaries 
Python :: pandas df describe() 
Python :: pytest temp directory 
Python :: python check variable size in memory 
Python :: pyqt tutorial 
Python :: realtime output subprocess 
Python :: reset index python 
Python :: split path in list of directories 
Python :: how to slice dataframe by timestamp 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =