From f1b8c1965df2b8125761251aa6c76af1aa5e56ee Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 13 Jan 2020 14:07:42 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7=EF=BC=88=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=B5=84=E4=BA=A7=EF=BC=89=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/admin_user.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/assets/api/admin_user.py b/apps/assets/api/admin_user.py index 52b05fcd4..c77da1ae4 100644 --- a/apps/assets/api/admin_user.py +++ b/apps/assets/api/admin_user.py @@ -16,6 +16,8 @@ from django.db import transaction from django.db.models import Count from django.shortcuts import get_object_or_404 +from django.utils.translation import ugettext as _ +from rest_framework import status from rest_framework.response import Response from orgs.mixins.api import OrgBulkModelViewSet from orgs.mixins import generics @@ -50,6 +52,14 @@ class AdminUserViewSet(OrgBulkModelViewSet): queryset = queryset.annotate(_assets_amount=Count('assets')) return queryset + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + has_related_asset = instance.assets.exists() + if has_related_asset: + data = {'msg': _('Deleted failed, There are related assets')} + return Response(data=data, status=status.HTTP_400_BAD_REQUEST) + return super().destroy(request, *args, **kwargs) + class AdminUserAuthApi(generics.UpdateAPIView): model = AdminUser