Taking advantage of generic classes and viewsets
Now, we will create many Django class-based views that will use the previously explained generic classes combined with the serializer classes to return JSON representations for each HTTP request that our RESTful Web Service will handle.
We will just have to specify a queryset that retrieves all the objects in the queryset
attribute and the serializer class in the serializer_class
attribute for each subclass that we declare. The behavior coded in the generic classes will do the rest for us. In addition, we will declare a name
attribute with the string name we will use to identify the view.
Go to the restful01/drones
folder and open the views.py
file. Replace the code in this file with the following code that declares the required imports and the class-based views for our web service. We will add more classes to this file later. The code file for the sample is included in the hillar_django_restful_06_01
folder in the restful01/drones/views.py
...