Creating the Post Model
Understand the requirements for creating a post feature in Django and utilize abstraction to reduce code duplication.
A post in this project is a long or short piece of text that can be viewed by anyone, irrespective of whether a user is linked or associated to that post.
Feature requirements
Here are the requirements for the post feature:
Authenticated users should be able to create a post.
Authenticated users should be able to like the post.
All users should be able to read the post, even if they aren’t authenticated.
The author of the post should be able to modify the post.
The author of the post should be able to delete the post.
Looking at these requirements from a backend perspective, we can understand that we’ll be dealing with a database, a model, and permissions. First, let’s start by writing the structure of the Post
model in the database.
Designing the Post
model
A post consists of content made up of characters written by an author (here, a user). How does that schematize itself into our database?
Before creating the Post
model, let’s draw a quick figure of the structure of the model in the database:
Get hands-on with 1400+ tech skills courses.