ER
ORM
models.py
from django.db import models
class User(models.Model):
username = models.CharField(max_length=255)
email = models.EmailField()
password = models.CharField(max_length=255)
bio = models.CharField(max_length=255)
class Tweet(models.Model):
content = models.TextField()
created_at = models.DateTimeField()
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='tweets')
class Tag(models.Model):
tag_name = models.CharField(max_length=255)
tweets = models.ManyToManyField(Tweet, related_name='tags')
class UserFollowsUser(models.Model):
follower = models.ForeignKey(User, on_delete=models.CASCADE, related_name='following')
followee = models.ForeignKey(User, on_delete=models.CASCADE, related_name='followers')
class Like(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='likes')
tweet = models.ForeignKey(Tweet, on_delete=models.CASCADE, related_name='likes')