Declaring relationships with the models
Make sure you quit the Django's development server. Remember that you just need to press
Ctrl
+
C
in the terminal or command-prompt window in which it is running. Now, we will create the models that we are going to use to represent and persist the game categories, games, players and scores, and their relationships. Open the games/models.py
file and replace its contents with the following code. The lines that declare fields related to other models are highlighted in the code listing. The code file for the sample is included in the restful_python_chapter_02_03
folder.
from django.db import models class GameCategory(models.Model): name = models.CharField(max_length=200) class Meta: ordering = ('name',) def ...
Get Building RESTful Python Web Services 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.