From 24de92aa741c4bf15edfe4c594b2dfd7744b9bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Sat, 20 Mar 2021 16:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dvadmin-backend/apps/vadmin/op_drf/mixins.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dvadmin-backend/apps/vadmin/op_drf/mixins.py b/dvadmin-backend/apps/vadmin/op_drf/mixins.py index 5bc65ef..1489d83 100644 --- a/dvadmin-backend/apps/vadmin/op_drf/mixins.py +++ b/dvadmin-backend/apps/vadmin/op_drf/mixins.py @@ -93,11 +93,25 @@ class DestroyModelMixin(mixins.DestroyModelMixin): """ destroy_serializer_class = None + def get_object_list(self): + queryset = self.filter_queryset(self.get_queryset()) + lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field + assert lookup_url_kwarg in self.kwargs, ( + 'Expected view %s to be called with a URL keyword argument ' + 'named "%s". Fix your URL conf, or set the `.lookup_field` ' + 'attribute on the view correctly.' % + (self.__class__.__name__, lookup_url_kwarg) + ) + filter_kwargs = {f"{self.lookup_field}__in": self.kwargs[lookup_url_kwarg].split(',')} + obj = queryset.filter(**filter_kwargs) + self.check_object_permissions(self.request, obj) + return obj + def destroy(self, request: Request, *args, **kwargs): - instance = self.get_object() - self.perform_destroy(instance) + instance = self.get_object_list() if hasattr(self, 'handle_logging'): self.handle_logging(request, instance=instance, *args, **kwargs) + self.perform_destroy(instance) return SuccessResponse(status=status.HTTP_204_NO_CONTENT) def perform_destroy(self, instance):