From ac4a321225d6e9bb26578c4271a33f68cf860a3a Mon Sep 17 00:00:00 2001 From: Bai Date: Tue, 14 Feb 2023 18:13:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=94=A8=E6=88=B7=E6=95=B0=E9=87=8F=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/api/role.py | 6 ++++-- apps/rbac/models/role.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/rbac/api/role.py b/apps/rbac/api/role.py index 97c0c76e3..3340a37fd 100644 --- a/apps/rbac/api/role.py +++ b/apps/rbac/api/role.py @@ -69,8 +69,10 @@ class RoleViewSet(JMSModelViewSet): role.users_amount = role_user_amount_mapper.get(role.id, 0) return queryset - def page_queryset(self, queryset): - queryset = super().page_queryset(queryset) + def paginate_queryset(self, queryset): + page_queryset = super().paginate_queryset(queryset) # 返回是 list 对象 + page_queryset_ids = [str(i.id) for i in page_queryset] + queryset = queryset.filter(id__in=page_queryset_ids) queryset = self.set_users_amount(queryset) return queryset diff --git a/apps/rbac/models/role.py b/apps/rbac/models/role.py index 85ccf590c..1eff7c15c 100644 --- a/apps/rbac/models/role.py +++ b/apps/rbac/models/role.py @@ -102,7 +102,7 @@ class Role(JMSBaseModel): @lazyproperty def users_amount(self): - return 0 + return self.users.count() @lazyproperty def permissions_amount(self):