Creating the models
Now, we will create a simple Game
model that we will use to represent and persist games. Open the games/models.py
file. The following lines show the initial code for this file, with just one import statement and a comment that indicates we should create the models:
from django.db import models # Create your models here.
The following lines show the new code that creates a Game
class, specifically, a Game
model in the games/models.py
file. The code file for the sample is included in the restful_python_chapter_01_01
folder:
from django.db import models class Game(models.Model): created = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=200, blank=True, default='') release_date = models.DateTimeField() ...
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.