1👍
✅
Class Conversation(models.Model):
user1, user2 =; # this is from User table
...... # many other attribute
Class Message(models.Model):
sender, reciever ; # this is user ID from User Model
...... # many other attribute
conversation = models.ForeignKey(Conversation, on_delete=models.CASCADE, related_name='messages')
To see the messages of a conversation instance, you can follow the relationship backward like this
conversation = Conversation.objects.get(...)
conversation_messages = conversation.messages.all()
Source:stackexchange.com