當前位置: 首頁>>代碼示例>>Python>>正文


Python PageNumberPagination.page_size方法代碼示例

本文整理匯總了Python中rest_framework.pagination.PageNumberPagination.page_size方法的典型用法代碼示例。如果您正苦於以下問題:Python PageNumberPagination.page_size方法的具體用法?Python PageNumberPagination.page_size怎麽用?Python PageNumberPagination.page_size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.pagination.PageNumberPagination的用法示例。


在下文中一共展示了PageNumberPagination.page_size方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: paginated_queryset

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import page_size [as 別名]
def paginated_queryset(queryset, request):
	"""
	Return a paginated queryset.
	"""
	paginator = PageNumberPagination()
	paginator.page_size = settings.REST_FRAMEWORK['PAGE_SIZE']
	result_page = paginator.paginate_queryset(queryset, request)
	return (paginator, result_page)
開發者ID:ncs-jss,項目名稱:HTTP_200,代碼行數:10,代碼來源:pagination.py

示例2: diffs

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import page_size [as 別名]
def diffs(request, doctype_name, dataset_name):
    queryset = TreeNode.objects.select_related(
        'dataset', 'tree2_diffs'
    ).filter(
        dataset__doctype__name=doctype_name,
        dataset__name=dataset_name,
        tree2_diffs__isnull=False
    )

    paginator = PageNumberPagination()
    paginator.page_size = 1

    result_page = paginator.paginate_queryset(queryset, request)
    serializer = KeySerializer(result_page, many=True)

    return paginator.get_paginated_response(serializer.data)
開發者ID:classifaddict,項目名稱:classifactory,代碼行數:18,代碼來源:views.py

示例3: plans

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import page_size [as 別名]
    def plans(self, request, pk, *args, **kwargs):
        batch = get_object_or_404(Batch, id=pk)
        plans = Internship.objects.filter(intern__batch=batch).prefetch_related(
            'rotation_requests__requested_department__department__hospital',
            'rotation_requests__requested_department__department__specialty',
            'rotation_requests__response',
            'rotation_requests__forward',
            'rotations__department__specialty',
            'rotations__department__hospital',
            'intern__profile__user__freezes',
            'intern__profile__user__freeze_requests__response',
            'intern__profile__user__freeze_cancel_requests__response',
            'intern__profile__user__leaves',
            'intern__profile__user__leave_requests__response',
            'intern__profile__user__leave_cancel_requests__response',
            'intern__university',
            'intern__batch',
        ).order_by(
            Lower('intern__profile__en_first_name'),
            Lower('intern__profile__en_father_name'),
            Lower('intern__profile__en_grandfather_name'),
            Lower('intern__profile__en_last_name'),
        )

        filtered = InternshipFilter({'intern__profile__en_full_name': request.query_params.get('query')}, plans)

        paginator = PageNumberPagination()
        paginator.page_size = 10
        page = paginator.paginate_queryset(filtered.qs, request)

        if page is not None:
            serialized = FullInternshipSerializer2(page, many=True)
            return paginator.get_paginated_response(serialized.data)

        serialized = FullInternshipSerializer2(filtered.qs, many=True)
        return Response(serialized.data)
開發者ID:msarabi95,項目名稱:easy-internship,代碼行數:38,代碼來源:views.py

示例4: element_fancy_search

# 需要導入模塊: from rest_framework.pagination import PageNumberPagination [as 別名]
# 或者: from rest_framework.pagination.PageNumberPagination import page_size [as 別名]
def element_fancy_search(request, query):
    """
    List all ancestors' pk of the first element found.
    """

    queryset = TreeNode.objects.only('id')

    for param in query.split():
        if '!' in param:
            p = param.split('!')
            if len(p) > 2:
                break
            queryset = queryset.filter(
                dataset__doctype__name=p[0],
                dataset__name=p[1]
            )
        elif '@' in param:
            # Search specified element by attribute
            p = param.split('@')
            if len(p) > 2:
                continue
            if p[0] and p[1]:
                if '=' in p[1]:
                    a = p[1].split('=')
                    if len(a) > 2:
                        continue
                    if a[0] and a[1]:
                        # '[email protected]=v' Search specified element by attribute name and value
                        queryset = queryset.filter(
                            element__type__name=p[0],
                            element__attributes__type__name=a[0],
                            element__attributes__value=a[1]
                        )
                    elif a[1]:
                        # '[email protected]=v' Search specified element by attribute value
                        queryset = queryset.filter(
                            element__type__name=p[0],
                            element__attributes__value=a[1]
                        )
                else:
                    # '[email protected]' Search specified element by attribute name
                    queryset = queryset.filter(
                        element__type__name=p[0],
                        element__attributes__type__name=p[1],
                    )
            elif p[1]:
                # Search any element by attribute
                if '=' in p[1]:
                    a = p[1].split('=')
                    if len(a) > 2:
                        continue
                    if a[0] and a[1]:
                        # '@a=v' Search any element by attribute name and value
                        queryset = queryset.filter(
                            element__attributes__type__name=a[0],
                            element__attributes__value=a[1]
                        )
                    elif a[1]:
                        # '@=v' Search any element by attribute value
                        queryset = queryset.filter(
                            element__attributes__value=a[1]
                        )
                else:
                    # '@a' Search any element by attribute name
                    queryset = queryset.filter(
                        element__attributes__type__name=p[1]
                    )
            else:
                # '@' Search any element with attribute
                queryset = queryset.filter(
                    element__attributes__isnull=False
                )
        else:
            # if '=' in p[1]:
                # 'e=t' Search element by content
            # else:
            # 'e' Search specified element by name
            queryset = queryset.filter(
                element__type__name=param
            )

    paginator = PageNumberPagination()
    paginator.page_size = 1

    result_page = paginator.paginate_queryset(queryset, request)
    serializer = KeySerializer(result_page, many=True)

    return paginator.get_paginated_response(serializer.data)
開發者ID:classifaddict,項目名稱:classifactory,代碼行數:90,代碼來源:views.py


注:本文中的rest_framework.pagination.PageNumberPagination.page_size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。