Creating models for the database
We will start by building two tables in the database: Post
, which will contain the articles, and Comment
, so that readers can leave their opinions next to the articles.
In app/website/models.py
, add the following database structure:
from django.db import models from django.utils.text import slugify from django.urls import reverse class Post(models.Model): # Fields: Title of the article, name of the author, content of the article and date of creation. title = models.CharField(max_length=200, unique=True) author = models.CharField(max_length=20) content = models.TextField() created_at = models.DateTimeField(auto_now_add=True) class Meta: ordering = ["-created_at"] @property ...