From 2ae3044d9d4dfb8371055513e440e0384f211963 Mon Sep 17 00:00:00 2001 From: wookkl Date: Wed, 12 Mar 2025 00:53:04 +0900 Subject: Fixed #35945 -- Added async interface to Paginator. --- docs/ref/paginator.txt | 46 ++++++++++++++++++++++++++++++++++++++++++++++ docs/releases/6.0.txt | 8 ++++++++ 2 files changed, 54 insertions(+) (limited to 'docs') diff --git a/docs/ref/paginator.txt b/docs/ref/paginator.txt index 03084e5d40..d5b5b0f30e 100644 --- a/docs/ref/paginator.txt +++ b/docs/ref/paginator.txt @@ -161,6 +161,30 @@ Attributes A 1-based range iterator of page numbers, e.g. yielding ``[1, 2, 3, 4]``. +``AsyncPaginator`` class +======================== + +.. versionadded:: 6.0 + +.. class:: AsyncPaginator(object_list, per_page, orphans=0, allow_empty_first_page=True, error_messages=None) + + Asynchronous version of :class:`Paginator`. + + ``AsyncPaginator`` has the same attributes and signatures as + :class:`Paginator`, with the following exceptions: + + * The attribute :attr:`.Paginator.count` is supported as an asynchronous + method ``AsyncPaginator.acount()``. + * The attribute :attr:`.Paginator.num_pages` is supported as an + asynchronous method ``AsyncPaginator.anum_pages()``. + * The attribute :attr:`.Paginator.page_range` is supported as an + asynchronous method ``AsyncPaginator.apage_range()``. + + ``AsyncPaginator`` has asynchronous versions of the same methods as + :class:`Paginator`, using an ``a`` prefix - for example, use + ``await async_paginator.aget_page(number)`` rather than + ``paginator.get_page(number)``. + ``Page`` class ============== @@ -226,6 +250,28 @@ Attributes The associated :class:`Paginator` object. +``AsyncPage`` class +=================== + +.. versionadded:: 6.0 + +.. class:: AsyncPage(object_list, number, paginator) + + Asynchronous version of :class:`Page`. + + ``AsyncPage`` has the same attributes and signatures as :class:`Page`, as + well as asynchronous versions of all the same methods, using an ``a`` + prefix - for example, use ``await async_page.ahas_next()`` rather than + ``page.has_next()``. + + ``AsyncPage`` has the following additional method: + + .. method:: AsyncPage.aget_object_list() + + Returns ``AsyncPage.object_list`` as a list. This method must be + awaited before ``AsyncPage`` can be treated as a sequence of + ``AsyncPage.object_list``. + Exceptions ========== diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index 9e74856664..c604638deb 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -199,6 +199,14 @@ Models :ref:`a forced update ` results in no affected rows, instead of a generic :exc:`django.db.DatabaseError`. +Pagination +~~~~~~~~~~ + +* The new :class:`~django.core.paginator.AsyncPaginator` and + :class:`~django.core.paginator.AsyncPage` provide async implementations of + :class:`~django.core.paginator.Paginator` and + :class:`~django.core.paginator.Page` respectively. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3