Persisting the user that makes a request and configuring permission policies

We want to be able to list all the users and retrieve the details for a single user. We will create subclasses of the two following generic class views declared in the rest_framework.generics module:

  • ListAPIView: Implements the get method that retrieves a listing of  queryset
  • RetrieveAPIView: Implements the get method to retrieve a model instance

Open the views.py file in the games_service/games folder. Add the following code after the last line that declares the imports, before the declaration of the GameCategoryList class. The code file for the sample is included in the restful_python_2_07_04 folder, in the Django01/games-service/games/views.py file:

from django.contrib.auth.models ...

Get Hands-On RESTful Python Web Services - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.