Working with class-based views
We will write our RESTful Web Service by coding class-based views. We will take advantage of a set of generic views that we can use as our base classes for our class-based views to reduce the required code to the minimum and reuse the behavior that has been generalized in the Django REST framework.
We will create subclasses of the two following generic class views declared in the rest_framework.generics
module:
ListCreateAPIView
: This class view implements theget
method that retrieves a listing of a queryset and thepost
method that creates a model instanceRetrieveUpdateDestroyAPIView
: This class view implements theget
,delete
,put
, andpatch
methods to retrieve, delete, completely update, or partially update a model instance
Those two generic views are composed by combining reusable bits of behavior in the Django REST framework implemented as mixin classes declared in the rest_framework.mixins
module. We can create a class that uses multiple inheritance and...