Adding security-related data to the models

We will associate a game with a creator or owner. Only the authenticated users will be able to create new games. Only the creator of a game will be able to update it or delete it. All the requests that aren't authenticated will only have read-only access to games.

Open the models.py file in the games_service/games folder. Replace the code that declares the Game class with the following code. The new and edited lines are highlighted in the code listing. The code file for the sample is included in the restful_python_2_07_04 folder, in the Django01/games-service/games/models.py file:

class Game(models.Model): created = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=200, unique=True) ...

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.