本文整理汇总了Python中tastypie.paginator.Paginator.get_slice方法的典型用法代码示例。如果您正苦于以下问题:Python Paginator.get_slice方法的具体用法?Python Paginator.get_slice怎么用?Python Paginator.get_slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.paginator.Paginator
的用法示例。
在下文中一共展示了Paginator.get_slice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_custom_list
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import get_slice [as 别名]
def get_custom_list(self, request, queryset):
'''
Generic function to paginate a queryset with a set of items per page.
'''
self.method_check(request, allowed=['get'])
self.throttle_check(request)
# Do the query.
offset = int(request.GET.get('offset', 0))
limit = min(int(request.GET.get('limit', 20)), 1000)
paginator = Paginator(request.GET, queryset)
try:
object_list = paginator.get_slice(limit, offset)
except InvalidPage:
raise Http404("Sorry, no results on that page.")
objects = []
for result in object_list:
bundle = self.build_bundle(obj=result, request=request)
bundle = self.full_dehydrate(bundle)
objects.append(bundle)
page = {
"meta": {
"limit": limit,
"offset": offset,
"total_count": queryset.count()
},
'objects': objects,
}
self.log_throttled_access(request)
return self.create_response(request, page)