Creating our first model
Now, we will create a simple Toy
model in Django, which we will use to represent and persist toys. Open the toys/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 Toy
class, specifically, a Toy
model in the toys/models.py
file. The code file for the sample is included in the hillar_django_restful_02_01
folder in the restful01/toys/models.py
file:
from django.db import models class Toy(models.Model): created = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=150, blank=False, default='') description = models.CharField(max_length=250, blank=True, default='') toy_category = models.CharField(max_length=200, blank=False, default='') release_date = models.DateTimeField() was_included_in_home...