May 2018
Beginner to intermediate
526 pages
11h 57m
English
We will start designing our blog data schema by defining the data models for our blog. A model is a Python class that subclasses django.db.models.Model, in which each attribute represents a database field. Django will create a table for each model defined in the models.py file. When you create a model, Django provides you with a practical API to query objects in the database easily.
First, we will define a Post model. Add the following lines to the models.py file of the blog application:
from django.db import modelsfrom django.utils import timezonefrom django.contrib.auth.models import Userclass Post(models.Model): STATUS_CHOICES = ( ('draft', 'Draft'), ('published', 'Published'), ) title = models.CharField(max_length=250) ...Read now
Unlock full access