我的设置:
'DEFAULT_PAGINATION_CLASS': 'mobile_api.pagination.OptionalPageNumberPagination',
'PAGE_SIZE': 40`
我的课程:
来自rest_framework_json_api导入分页
class OptionalPageNumberPagination(pagination.PageNumberPagination):
def paginate_queryset(self, queryset, request, view=None):
if 'page' in request.query_params:
return super().paginate_queryset(queryset, request, view)
else:
return queryset
def get_paginated_response(self, data):
if hasattr(self, 'page'):
return super().get_paginated_response(data)
else:
from rest_framework.response import Response
from collections import OrderedDict
return Response(OrderedDict([
('results', data)
]))
如何使用订购?我的模型包含属性Cod,我想按它排序。
帮助。 :)