From 6f288e977f34d8a0bd0d151a71c3aea31b29d55c Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Fri, 24 Nov 2023 22:21:30 +0100 Subject: [PATCH] =?UTF-8?q?Ajoute=20une=20contrainte=20d'unicit=C3=A9=20su?= =?UTF-8?q?r=20PrivateTopicRead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0008_unique_privatetopicread.py | 16 ++++++++++++++++ zds/mp/models.py | 1 + 2 files changed, 17 insertions(+) create mode 100644 zds/mp/migrations/0008_unique_privatetopicread.py diff --git a/zds/mp/migrations/0008_unique_privatetopicread.py b/zds/mp/migrations/0008_unique_privatetopicread.py new file mode 100644 index 0000000000..486219dbdd --- /dev/null +++ b/zds/mp/migrations/0008_unique_privatetopicread.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.21 on 2023-11-24 22:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("mp", "0007_add_votes_to_private_post"), + ] + + operations = [ + migrations.AddConstraint( + model_name="privatetopicread", + constraint=models.UniqueConstraint(fields=("privatetopic", "user"), name="unique_privatetopicread"), + ), + ] diff --git a/zds/mp/models.py b/zds/mp/models.py index f1c8bbff0c..1bdcd7bbae 100644 --- a/zds/mp/models.py +++ b/zds/mp/models.py @@ -512,6 +512,7 @@ class PrivateTopicRead(models.Model): class Meta: verbose_name = "Message privé lu" verbose_name_plural = "Messages privés lus" + constraints = [models.UniqueConstraint(fields=["privatetopic", "user"], name="unique_privatetopicread")] privatetopic = models.ForeignKey(PrivateTopic, db_index=True, on_delete=models.CASCADE) privatepost = models.ForeignKey(PrivatePost, db_index=True, on_delete=models.CASCADE)