From 7550f31f604fa45f9030a32b9b8fbc2d0739bed7 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 9 Sep 2024 17:24:53 +0100 Subject: subscription and user is now uniquely constrained --- pyblackbird_cc/payments/models.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pyblackbird_cc/payments/models.py') diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py index cbf462c..174e3fe 100644 --- a/pyblackbird_cc/payments/models.py +++ b/pyblackbird_cc/payments/models.py @@ -57,5 +57,8 @@ class Subscription(models.Model): start_date = models.DateTimeField(null=True, blank=True) end_date = models.DateTimeField(null=True, blank=True) + class Meta: + constraints = [models.UniqueConstraint(fields=["user", "plan"], name="unique_user_plan")] + def __str__(self): return f"Subscription for {self.user.username}" -- cgit v1.2.3