python 2.7 - "get_paginated_response" in django-rest-framework 3.0 -


in drf 3.1 can paginated response seems get_paginated_response() not available in 3.0. equivalent?

class notelist(listcreateapiview):      def list(self, request, *args, **kwargs):         queryset = self.get_queryset()         paged_queryset = self.paginate_queryset(queryset)         serializer = noteserializer(paged_queryset, many=true)         return self.get_paginated_response(serializer.data) 

it's paginationserializer, set serializer class by:

'default_pagination_serializer_class': 'yourcustompaginationserializer'

or

class myview(generics.genericapiview):     pagination_serializer_class = yourcustompaginationserializerclass 

mixin.py

def list(self, request, *args, **kwargs):     instance = self.filter_queryset(self.get_queryset())     page = self.paginate_queryset(instance)     if page not none:         serializer = self.get_pagination_serializer(page)     else:         serializer = self.get_serializer(instance, many=true)     return response(serializer.data) 

generics.py

def get_pagination_serializer(self, page):     """     return serializer instance use paginated data.     """     class serializerclass(self.pagination_serializer_class):         class meta:             object_serializer_class = self.get_serializer_class()      pagination_serializer_class = serializerclass     context = self.get_serializer_context()     return pagination_serializer_class(instance=page, context=context) 

if doing migration stuffs, don't forget pagination params in settings.py or view, has been changed new paginator.

such as. paginate_by_param -> page_size_query_param.

anyhow, think new paginator confortable previous one. see more detials on pagination docs


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -