2
0
Jeremy Stretch 7 жил өмнө
parent
commit
f664998d9b

+ 4 - 10
netbox/utilities/api.py

@@ -9,18 +9,15 @@ from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.exceptions import ObjectDoesNotExist
 from django.db.models import ManyToManyField
 from django.db.models import ManyToManyField
 from django.http import Http404
 from django.http import Http404
-from rest_framework import mixins
 from rest_framework.exceptions import APIException
 from rest_framework.exceptions import APIException
 from rest_framework.permissions import BasePermission
 from rest_framework.permissions import BasePermission
 from rest_framework.relations import PrimaryKeyRelatedField
 from rest_framework.relations import PrimaryKeyRelatedField
 from rest_framework.response import Response
 from rest_framework.response import Response
 from rest_framework.serializers import Field, ModelSerializer, RelatedField, ValidationError
 from rest_framework.serializers import Field, ModelSerializer, RelatedField, ValidationError
-from rest_framework.viewsets import GenericViewSet, ViewSet
+from rest_framework.viewsets import ModelViewSet as _ModelViewSet, ViewSet
 
 
 from .utils import dynamic_import
 from .utils import dynamic_import
 
 
-WRITE_OPERATIONS = ['create', 'update', 'partial_update', 'delete']
-
 
 
 class ServiceUnavailable(APIException):
 class ServiceUnavailable(APIException):
     status_code = 503
     status_code = 503
@@ -188,19 +185,16 @@ class WritableNestedSerializer(ModelSerializer):
 # Viewsets
 # Viewsets
 #
 #
 
 
-class ModelViewSet(mixins.CreateModelMixin,
-                   mixins.RetrieveModelMixin,
-                   mixins.UpdateModelMixin,
-                   mixins.DestroyModelMixin,
-                   mixins.ListModelMixin,
-                   GenericViewSet):
+class ModelViewSet(_ModelViewSet):
     """
     """
     Accept either a single object or a list of objects to create.
     Accept either a single object or a list of objects to create.
     """
     """
     def get_serializer(self, *args, **kwargs):
     def get_serializer(self, *args, **kwargs):
+
         # If a list of objects has been provided, initialize the serializer with many=True
         # If a list of objects has been provided, initialize the serializer with many=True
         if isinstance(kwargs.get('data', {}), list):
         if isinstance(kwargs.get('data', {}), list):
             kwargs['many'] = True
             kwargs['many'] = True
+
         return super(ModelViewSet, self).get_serializer(*args, **kwargs)
         return super(ModelViewSet, self).get_serializer(*args, **kwargs)