Skip to content

How to make Paginated response from queryset ? #195

@Elixir-MeetThoriya

Description

@Elixir-MeetThoriya
   @http_get(
        path="",
        response={
            HTTPStatus.OK: PaginatedResponseSchema[CountrySchema] | List[CountrySchema],
            HTTPStatus.INTERNAL_SERVER_ERROR: ErrorSchema
        },
        summary="Country List",
        description="This endpoint retrieves a list of countries.",
        url_name="country_list"
    )
    # @paginate()  # use default pagination (which define in setting.py)
    @ordering(Ordering, ordering_fields=['name', 'code'])
    @searching(Searching, search_fields=['name', 'code'])
    def list(self):
        try:
            if self.request.headers.get('no_page') == 1:
                return self.model.objects.all()
            else:
                return .................

Hiiii @eadwinCode
this is my list api ..
default pagination class = from ninja_extra.pagination import PageNumberPaginationExtra
i need to send condition base response (paginated or non-paginated)
so in my list api-function how to make a paginated response, without using "@paginate" decorator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions