2023-11-27 17:31:31 -05:00
|
|
|
from django.db import models
|
2023-12-12 04:05:13 -05:00
|
|
|
from django.db.models import IntegerField
|
|
|
|
from django.contrib.auth.models import User
|
2023-12-15 14:32:43 -05:00
|
|
|
from django.contrib import admin
|
2023-11-27 17:31:31 -05:00
|
|
|
|
|
|
|
# Create your models here.
|
2023-12-27 10:14:39 -05:00
|
|
|
class ChatChannelModel(models.Model):
|
|
|
|
|
|
|
|
def create(self, users_id: [int]):
|
|
|
|
self.save()
|
|
|
|
for user_id in users_id:
|
|
|
|
ChatMemberModel(channel_id = self.pk, member_id = user_id).save()
|
2023-12-12 04:05:13 -05:00
|
|
|
|
2023-12-27 10:14:39 -05:00
|
|
|
def get_members_id(self):
|
|
|
|
return [member_channel.member_id for member_channel in ChatMemberModel.objects.filter(channel_id = self.pk)]
|
|
|
|
|
|
|
|
class ChatMemberModel(models.Model):
|
2023-12-12 04:05:13 -05:00
|
|
|
member_id = IntegerField(primary_key=False)
|
|
|
|
channel_id = IntegerField(primary_key=False)
|
|
|
|
|
2023-12-15 14:32:43 -05:00
|
|
|
def __str__(self):
|
|
|
|
return "member_id: " + str(self.member_id) + ", channel_id: " + str(self.channel_id)
|
|
|
|
|
2023-12-27 10:14:39 -05:00
|
|
|
class ChatMessageModel(models.Model):
|
2023-12-12 04:05:13 -05:00
|
|
|
channel_id = IntegerField(primary_key=False)
|
|
|
|
author_id = IntegerField(primary_key=False)
|
|
|
|
content = models.CharField(max_length=255)
|
2023-12-15 14:32:43 -05:00
|
|
|
time = IntegerField(primary_key=False)
|
|
|
|
|
2023-12-19 05:27:18 -05:00
|
|
|
def __str__(self):
|
2023-12-27 10:14:39 -05:00
|
|
|
return "author_id: " + str(self.author_id) + ", channel_id: " + str(self.channel_id) + ", content: " + self.content
|