E
E
Egorian2018-12-13 19:43:25
Django
Egorian, 2018-12-13 19:43:25

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"

Did you implement the structure for the chat correctly? Is the content_id needed or does the Message id replace it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question