From e0e78e2ca026898ed2cfd75dcc75977611cc0d38 Mon Sep 17 00:00:00 2001 From: "Ph. SW" Date: Sun, 10 Dec 2023 17:37:05 +0100 Subject: [PATCH] =?UTF-8?q?Ajoute=20une=20contrainte=20d'unicit=C3=A9=20su?= =?UTF-8?q?r=20PrivateTopicRead=20(#6558)?= 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)