What is the best way to implement these models?

I am trying to create a social media app where users can sign up, make posts, view others post, like and unlike other Users posts.

What would be the best way to implement the models for the like and unlike feature? Initially, I created a post model in a post app and two models: like and unlike in a reactions app. Do you think this is a good idea?

I think you should start by studying the documentation. Free video courses will be a good addition. As for the rest of the question, you will find models in Django. In simplest terms, your models could look like this.

from django.db import models

class User(models.Model):
    name = models.CharField(max_length=40)
    surname = models.CharField(max_length=40)

class Post(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=100)
    content = models.TextField()
    like = models.SmallIntegerField()
    unlike = models.SmallIntegerField()

As you can see, you have two classes that represent the User and Post model. Classes have specific fields and models are related to each other.

Back to Top