Saving information about users that make requests
Whenever a user performs an HTTP POST request to the drone resource collection to create a new drone resource, we want to make the authenticated user that makes the request the owner of the new drone. In order to make this happen, we will override the perform_create method in the DroneList class declared in the views.py file.
Open the restful01/drones/views.py file and replace the code that declares the DroneList class with the following code. The new lines are highlighted in the code listing. The code file for the sample is included in the hillar_django_restful_08_01 folder, in the restful01/drones/views.py file:
class DroneList(generics.ListCreateAPIView):
queryset = Drone.objects.all()
serializer_class = DroneSerializer
name = 'drone-list'
filter_fields = (
'name',
'drone_category',
'manufacturing_date',
'has_it_competed',
)
search_fields = (
'^name',
...