From 4e9012cc074c815c0e1612fd2fbf29d2320a3e62 Mon Sep 17 00:00:00 2001 From: "fangfang.dong" Date: Tue, 27 Jun 2023 10:45:50 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8E=A5=E5=8F=A3sql=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20/api/v1/accounts/account-templates/su-from-account-templates?= =?UTF-8?q?/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/api/account/template.py | 3 +-- apps/accounts/models/account.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/accounts/api/account/template.py b/apps/accounts/api/account/template.py index 0aecb5143..1d2508764 100644 --- a/apps/accounts/api/account/template.py +++ b/apps/accounts/api/account/template.py @@ -49,8 +49,7 @@ class AccountTemplateViewSet(OrgBulkModelViewSet): @action(methods=['get'], detail=False, url_path='su-from-account-templates') def su_from_account_templates(self, request, *args, **kwargs): pk = request.query_params.get('template_id') - template = AccountTemplate.objects.filter(pk=pk).first() - templates = AccountTemplate.get_su_from_account_templates(template) + templates = AccountTemplate.get_su_from_account_templates(pk) templates = self.filter_queryset(templates) serializer = self.get_serializer(templates, many=True) return Response(data=serializer.data) diff --git a/apps/accounts/models/account.py b/apps/accounts/models/account.py index 30eb853e3..81300e747 100644 --- a/apps/accounts/models/account.py +++ b/apps/accounts/models/account.py @@ -124,10 +124,10 @@ class AccountTemplate(BaseAccount): ] @classmethod - def get_su_from_account_templates(cls, instance=None): - if not instance: + def get_su_from_account_templates(cls, pk=None): + if pk is None: return cls.objects.all() - return cls.objects.exclude(Q(id=instance.id) | Q(su_from=instance)) + return cls.objects.exclude(Q(id=pk) | Q(_id=pk)) def get_su_from_account(self, asset): su_from = self.su_from