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):