From 39253a205cc040f6719f67ce4e525d03f8f33232 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 2 Sep 2024 18:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20`total`=20parameter=20for?= =?UTF-8?q?=20tortoise=20ext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi_pagination/ext/tortoise.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastapi_pagination/ext/tortoise.py b/fastapi_pagination/ext/tortoise.py index d7cb50e8..f8cacd3f 100644 --- a/fastapi_pagination/ext/tortoise.py +++ b/fastapi_pagination/ext/tortoise.py @@ -35,13 +35,14 @@ async def paginate( *, transformer: Optional[AsyncItemsTransformer] = None, additional_data: Optional[AdditionalData] = None, + total: Optional[int] = None, ) -> Any: params, raw_params = verify_params(params, "limit-offset") if not isinstance(query, QuerySet): query = query.all() - - total = await query.count() if raw_params.include_total else None + if total is None and raw_params.include_total: + total = await query.count() items = await generic_query_apply_params(_generate_query(query, prefetch_related), raw_params).all() t_items = await apply_items_transformer(items, transformer, async_=True)