From bce34a0c4020cbec210340105ffbfed8ff7ac3a8 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 18 Jun 2022 14:58:59 +0700 Subject: [PATCH] Fix chat_box schema --- .../migrations/0009_auto_20220618_1452.py | 24 +++++++++++++++++++ chat_box/models.py | 7 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 chat_box/migrations/0009_auto_20220618_1452.py diff --git a/chat_box/migrations/0009_auto_20220618_1452.py b/chat_box/migrations/0009_auto_20220618_1452.py new file mode 100644 index 0000000..f0d5e7e --- /dev/null +++ b/chat_box/migrations/0009_auto_20220618_1452.py @@ -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", + ), + ), + ] diff --git a/chat_box/models.py b/chat_box/models.py index 132992a..493ebfb 100644 --- a/chat_box/models.py +++ b/chat_box/models.py @@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _ from judge.models.profile import Profile -__all__ = ["Message"] +__all__ = ["Message", "Room", "UserRoom", "Ignore"] class Room(models.Model): @@ -57,11 +57,12 @@ class UserRoom(models.Model): class Ignore(models.Model): - user = models.ForeignKey( + user = models.OneToOneField( Profile, related_name="ignored_chat_users", verbose_name=_("user"), on_delete=CASCADE, + db_index=True, ) ignored_users = models.ManyToManyField(Profile) @@ -79,7 +80,7 @@ class Ignore(models.Model): @classmethod def get_ignored_users(self, user): try: - return self.objects.filter(user=user)[0].ignored_users.all() + return self.objects.get(user=user).ignored_users.all() except: return Profile.objects.none()