Answer the question
In order to leave comments, you need to log in
What should models.py look like for chat?
I make a social network for educational purposes. Here I read about how the database structure for a chat should look like.
This is what my models.py looks like
from django.db import models
# Create your models here.
class User(models.Model):
first_name=models.CharField(max_length=40)
second_name=models.CharField(max_length=40)
class Meta:
db_table="users"
class Message(models.Model):
to_id=models.ForeignKey(User,on_delete=models.CASCADE,related_name="reciever")
from_id=models.ForeignKey(User,on_delete=models.CASCADE,related_name="sender")
content_id=models.AutoField(primary_key=True)
class Meta:
db_table="messages"
class MessageContent(models.Model):
message=models.ForeignKey(Message,on_delete=models.CASCADE)
content=models.TextField()
class Meta:
db_table="contents"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question