Fix chat_box schema

This commit is contained in:
cuom1999 2022-06-18 14:58:59 +07:00
parent 289e9ab7db
commit bce34a0c40
2 changed files with 28 additions and 3 deletions

View file

@ -0,0 +1,24 @@
# Generated by Django 2.2.25 on 2022-06-18 07:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("chat_box", "0008_ignore"),
]
operations = [
migrations.AlterField(
model_name="ignore",
name="user",
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="ignored_chat_users",
to="judge.Profile",
verbose_name="user",
),
),
]

View file

@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
from judge.models.profile import Profile from judge.models.profile import Profile
__all__ = ["Message"] __all__ = ["Message", "Room", "UserRoom", "Ignore"]
class Room(models.Model): class Room(models.Model):
@ -57,11 +57,12 @@ class UserRoom(models.Model):
class Ignore(models.Model): class Ignore(models.Model):
user = models.ForeignKey( user = models.OneToOneField(
Profile, Profile,
related_name="ignored_chat_users", related_name="ignored_chat_users",
verbose_name=_("user"), verbose_name=_("user"),
on_delete=CASCADE, on_delete=CASCADE,
db_index=True,
) )
ignored_users = models.ManyToManyField(Profile) ignored_users = models.ManyToManyField(Profile)
@ -79,7 +80,7 @@ class Ignore(models.Model):
@classmethod @classmethod
def get_ignored_users(self, user): def get_ignored_users(self, user):
try: try:
return self.objects.filter(user=user)[0].ignored_users.all() return self.objects.get(user=user).ignored_users.all()
except: except:
return Profile.objects.none() return Profile.objects.none()