AsyncPaginator
This class provides asynchronous pagination capabilities for object lists, extending the base pagination logic with coroutine-based methods. It supports asynchronous iteration over pages and provides awaitable methods for counting items, validating page numbers, and retrieving specific page objects. The class is designed to work with both standard sequences and objects that implement asynchronous count methods.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _cache_acount | integer = None | Internal cache for the total number of objects in the object_list to avoid redundant asynchronous count operations. |
| _cache_anum_pages | integer = None | Internal cache for the total number of pages calculated based on the object count and pagination settings. |
Constructor
Signature
def AsyncPaginator(
object_list: Any,
per_page: int,
orphans: int = 0,
allow_empty_first_page: bool = True,
error_messages: dict = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| object_list | Any | A list, tuple, or other sequence-like object to be paginated. |
| per_page | int | The maximum number of items to include on a single page. |
| orphans | int = 0 | The minimum number of items allowed on the last page. |
| allow_empty_first_page | bool = True | Whether the first page is allowed to be empty. |
| error_messages | dict = None | Optional dictionary of custom error messages. |
Methods
avalidate_number()
@classmethod
def avalidate_number(
number: int|str
) - > int
Validates the given page number against the total number of pages in the result set.
Parameters
| Name | Type | Description |
|---|---|---|
| number | `int | str` |
Returns
| Type | Description |
|---|---|
int | The validated page number as an integer |
aget_page()
@classmethod
def aget_page(
number: int|str
) - > [AsyncPage](asyncpage.md?sid=django_core_paginator_asyncpage)
See Paginator.get_page().
Parameters
| Name | Type | Description |
|---|---|---|
| number | `int | str` |
Returns
| Type | Description |
|---|---|
[AsyncPage](asyncpage.md?sid=django_core_paginator_asyncpage) | The requested page, or the first page if the input is invalid, or the last page if the input is out of range |
apage()
@classmethod
def apage(
number: int|str
) - > [AsyncPage](asyncpage.md?sid=django_core_paginator_asyncpage)
See Paginator.page().
Parameters
| Name | Type | Description |
|---|---|---|
| number | `int | str` |
Returns
| Type | Description |
|---|---|
[AsyncPage](asyncpage.md?sid=django_core_paginator_asyncpage) | An AsyncPage object containing the slice of objects for the specified page number |
acount()
@classmethod
def acount() - > int
See Paginator.count().
Returns
| Type | Description |
|---|---|
int | The total number of objects across all pages, cached after the first call |
anum_pages()
@classmethod
def anum_pages() - > int
See Paginator.num_pages().
Returns
| Type | Description |
|---|---|
int | The total number of pages calculated based on the count and items per page |
apage_range()
@classmethod
def apage_range() - > range
See Paginator.page_range()
Returns
| Type | Description |
|---|---|
range | A 1-based range object representing the sequence of available page numbers |
aget_elided_page_range()
@classmethod
def aget_elided_page_range(
number: int = 1,
on_each_side: int = 3,
on_ends: int = 2
) - > AsyncIterator[int|str]
Generates a page range with elided sections (ellipses) for use in large pagination sets.
Parameters
| Name | Type | Description |
|---|---|---|
| number | int = 1 | The current active page number around which to center the range |
| on_each_side | int = 3 | The number of pages to include on each side of the current page |
| on_ends | int = 2 | The number of pages to include at the beginning and end of the range |
Returns
| Type | Description |
|---|---|
| `AsyncIterator[int | str]` |