We will start by defining the initial 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 offers you a practical API to query the database easily.
First, we will define a
Post model. Add the following lines to the
models.py file of the
from django.db import modelsfrom django.utils import timezone from django.contrib.auth.models import User class Post(models.Model): STATUS_CHOICES = ( ('draft', 'Draft'), ('published', 'Published'), ) title = models.CharField(max_length=250) slug = models.SlugField(max_length=250, ...