Hi,
I am using DRF with no Django models, the reason is a legacy database that
has limited connection options (pyodbc only). I was hoping somebody could
help me figure out how to get the browsable API HTML controls for
pagination working.
What I have now is a subclassed GenericViewSet implementing list, along
with a custom serializer, custom database layer, and custom paginator:
class MyPaginator(LimitOffsetPagination):
def paginate_queryset(self, queryset, request, view=None):
self.limit = self.get_limit(request)
if self.limit is None:
return None
self.offset = self.get_offset(request)
self.count = queryset.count()
self.request = request
if self.count > self.limit and self.template is not None:
self.display_page_controls = True
if self.count == 0 or self.offset > self.count:
return []
#Add the limit/offset to the query
if self.limit:
queryset = queryset.limit(self.limit)
if self.offset:
queryset = queryset.offset(self.offset)
return list(queryset.execute())
from project.pagination import MyPaginator
from project.serializers import MySerializer
class MyViewSet(GenericViewSet):
serializer_class = MySerializer
pagination_class = MyPaginator
def get_queryset(self):
#Get the objects from the legacy DB
return Database().table("customers").all()
def list(self, request):
#Get the queryset (not a django queryset)
queryset = self.get_queryset()
#Run it through the paginator
paginator = pagination_class()
objects = paginator.paginate_queryset(queryset , request)
#Serialize the list of objects
serializer = self.serializer_class(objects, many=True)
#return Response(serializer.data)
return paginator.get_paginated_response(serializer.data)
This actually works well and the browsable API shows paginated data with
links to the next page. What I don't get is the HTMl pagination controls.
The docs say to set display_page_controls as True, but it is and no luck.
Anybody ever tried this, or have any ideas where I should look?
Thanks,
Angus
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.