From 796758cbb2c13d323366e296121651aa96753048 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Tue, 1 Nov 2022 11:13:18 +0800 Subject: [PATCH] perf: histories account --- apps/assets/api/account/account.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/assets/api/account/account.py b/apps/assets/api/account/account.py index 94b29995f..31aaccb96 100644 --- a/apps/assets/api/account/account.py +++ b/apps/assets/api/account/account.py @@ -1,6 +1,6 @@ from rest_framework.decorators import action from rest_framework.response import Response -from rest_framework.generics import CreateAPIView +from rest_framework.generics import CreateAPIView, get_object_or_404 from orgs.mixins.api import OrgBulkModelViewSet from rbac.permissions import RBACPermission @@ -41,7 +41,8 @@ class AccountSecretsViewSet(RecordViewLogMixin, AccountViewSet): 因为可能要导出所有账号,所以单独建立了一个 viewset """ serializer_classes = { - 'default': serializers.AccountSecretSerializer + 'default': serializers.AccountSecretSerializer, + 'histories': serializers.AccountHistorySerializer, } http_method_names = ['get', 'options'] # Todo: 记得打开 @@ -52,12 +53,11 @@ class AccountSecretsViewSet(RecordViewLogMixin, AccountViewSet): 'histories': ['assets.view_accountsecret'], } - @action(methods=['get'], detail=True, url_path='histories', serializer_class=serializers.AccountHistorySerializer) + @action(methods=['get'], detail=True, url_path='histories') def histories(self, request, *args, **kwargs): - account = self.get_object() - histories = account.history.all() - serializer = serializers.AccountHistorySerializer(histories, many=True) - return Response(serializer.data) + account = get_object_or_404(self.get_queryset(), **kwargs) + self.queryset = account.history.all() + return super().list(request, *args, **kwargs) class AccountTaskCreateAPI(CreateAPIView):