diff --git a/weblate/accounts/migrations/0014_alter_subscription_unique_together_and_more.py b/weblate/accounts/migrations/0014_alter_subscription_unique_together_and_more.py new file mode 100644 index 000000000000..ab0fecb4c7b9 --- /dev/null +++ b/weblate/accounts/migrations/0014_alter_subscription_unique_together_and_more.py @@ -0,0 +1,31 @@ +# Copyright © Michal Čihař +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# Generated by Django 5.1.4 on 2024-12-11 11:43 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("accounts", "0013_bot_notifications"), + ("trans", "0025_alter_announcement_notify"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="subscription", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="subscription", + constraint=models.UniqueConstraint( + fields=("notification", "scope", "project", "component", "user"), + name="accounts_subscription_notification_unique", + nulls_distinct=False, + ), + ), + ] diff --git a/weblate/accounts/models.py b/weblate/accounts/models.py index 8d44faa79793..48b2d00f3c07 100644 --- a/weblate/accounts/models.py +++ b/weblate/accounts/models.py @@ -187,9 +187,15 @@ class Subscription(models.Model): objects = SubscriptionQuerySet.as_manager() class Meta: - unique_together = [("notification", "scope", "project", "component", "user")] verbose_name = "Notification subscription" verbose_name_plural = "Notification subscriptions" + constraints = [ + models.UniqueConstraint( + name="accounts_subscription_notification_unique", + fields=("notification", "scope", "project", "component", "user"), + nulls_distinct=False, + ), + ] def __str__(self) -> str: return f"{self.user.username}:{self.get_scope_display()},{self.get_notification_display()} ({self.project},{self.component})"