Is it correct to use ViewSet and APINiew mixins on the same view in the Django REST Framework?

I am learning the Django REST Framework ( http://tomchristie.imtqy.com/rest-framework-2-docs/ , we are still on version 2.4). Is it right to define such a class, for example:

class UserView(generics.RetrieveUpdateDestroyAPIView,
               generics.ListCreateAPIView, 
               viewsets.GenericViewSet):
    # ... rest of class

In other words, is it right or possible to use * ViewSet and * APIView mixins / classes together, or are they intended as two completely different concepts that cannot be combined?

+4
source share
2 answers

Django REST API ViewSet , . , .

, , .

class UserView(mixins.CreateModelMixin, mixins.ListModelMixin,
               mixins.RetrieveModelMixin, mixins.DestroyModelMixin,
               mixins.UpdateModelMixin, 
               viewsets.GenericViewSet):

, Django REST ModelViewSet ReadOnlyModelViewSet, .

+5

, . .

ListCreateAPIView:

.

.

: GenericAPIView, ListModelMixin, CreateModelMixin

RetrieveUpdateDestroyAPIView:

get, put, patch delete.

: GenericAPIView, RetrieveModelMixin, UpdateModelMixin, DestroyModelMixin

GenericViewSet:

GenericViewSet GenericAPIView get_object, get_queryset , .

ModelViewSet:

ModelViewSet GenericAPIView , mixin.

, ModelViewSet, :.list(),.retrieve(),.create(),.update() .destroy().

ModelViewSet CRUD, .

, , . , , , . , mixins, API, mixins, Viewsets. Viewsets .

, :

class UserView(viewsets.ModelViewSet):
    .....
+6

All Articles