From f9494caa4066b2c38d12d4abb58ff44fd3f39e71 Mon Sep 17 00:00:00 2001 From: Arfey Date: Fri, 5 Apr 2024 03:26:25 +0300 Subject: [PATCH] fixed pagination for prefiltered selects --- .../postgres_resource/postgres_resource.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/aiohttp_admin2/resources/postgres_resource/postgres_resource.py b/aiohttp_admin2/resources/postgres_resource/postgres_resource.py index 2f40319..5e32fd4 100644 --- a/aiohttp_admin2/resources/postgres_resource/postgres_resource.py +++ b/aiohttp_admin2/resources/postgres_resource/postgres_resource.py @@ -162,10 +162,22 @@ async def get_list( res.append(self._row_to_instance(r, res)) if cursor is None: - count: int = await self._execute_scalar( - conn, - sa.select(func.count()).select_from(query) - ) + if filters: + count: int = await self._execute_scalar( + conn, + self.apply_filters( + query=( + sa.select(func.count(self._primary_key)) + .select_from(self.get_list_select()) + ), + filters=filters, + ) + ) + else: + count: int = await self._execute_scalar( + conn, + sa.select(func.count()).select_from(self.get_list_select()) + ) return self.create_paginator( instances=res, limit=limit,