ModelViewSet 响应封装()

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):
————————
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):