fix: 修改角色列表viewset排序问题

pull/9414/head
Bai 2023-02-02 16:28:54 +08:00 committed by Jiangjie.Bai
parent 2d514c0db0
commit c3d01591e7
2 changed files with 2 additions and 3 deletions

View File

@ -17,6 +17,7 @@ __all__ = [
class RoleViewSet(JMSModelViewSet): class RoleViewSet(JMSModelViewSet):
queryset = Role.objects.all() queryset = Role.objects.all()
ordering = ('-builtin', 'scope', 'name')
serializer_classes = { serializer_classes = {
'default': RoleSerializer, 'default': RoleSerializer,
'users': RoleUserSerializer, 'users': RoleUserSerializer,
@ -61,8 +62,7 @@ class RoleViewSet(JMSModelViewSet):
return super().perform_update(serializer) return super().perform_update(serializer)
def get_queryset(self): def get_queryset(self):
queryset = super().get_queryset() \ queryset = super().get_queryset().annotate(permissions_amount=Count('permissions'))
.annotate(permissions_amount=Count('permissions'))
return queryset return queryset
@action(methods=['GET'], detail=True) @action(methods=['GET'], detail=True)

View File

@ -43,7 +43,6 @@ class Role(JMSBaseModel):
class Meta: class Meta:
unique_together = [('name', 'scope')] unique_together = [('name', 'scope')]
ordering = ('-builtin', 'scope', 'name')
verbose_name = _('Role') verbose_name = _('Role')
def __str__(self): def __str__(self):