from utils.response import APIRespones
from rest_framework.viewsets import ModelViewSet
#统一请求成功返回模版
class MyModelViewSet(ModelViewSet):
def create(self, request, *args, **kwargs):
response = super().create(request, *args, **kwargs)
return APIRespones('1000', 'ok', True, response.data)
def list(self, request, *args, **kwargs):
response = super().list(request, *args, **kwargs)
return APIRespones('1000', 'ok', True, response.data)
def retrieve(self, request, *args, **kwargs):
response = super().retrieve(request, *args, **kwargs)
return APIRespones('1000', 'ok', True, response.data)
def update(self, request, *args, **kwargs):
response =super().update(request, *args, **kwargs)
return APIRespones('1000', 'ok', True, response.data)
def destroy(self, request, *args, **kwargs):
response = super().destroy(request, *args, **kwargs)
return APIRespones('1000', 'ok', True, response.data)
调用
views集成即可
class AddDepartmentTypeView2(MyModelViewSet):
标签:封装,request,args,ModelViewSet,响应,kwargs,APIRespones,data,response From: https://www.cnblogs.com/kaibindirver/p/16924994.html