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)