Implement handling callbacks

This commit is contained in:
2022-07-21 13:48:39 +01:00
parent 0b6f3ae129
commit 11b5eb50ec
14 changed files with 170 additions and 132 deletions

View File

@@ -23,10 +23,7 @@ class Plan(models.Model):
class User(AbstractUser):
# Stripe customer ID
stripe_id = models.CharField(max_length=255, null=True, blank=True)
subscription_id = models.CharField(max_length=255, null=True, blank=True)
subscription_active = models.BooleanField(null=True, blank=True)
last_payment = models.DateTimeField(null=True, blank=True)
paid = models.BooleanField(null=True, blank=True)
plans = models.ManyToManyField(Plan, blank=True)
email = models.EmailField(unique=True)
@@ -60,12 +57,13 @@ class User(AbstractUser):
super().delete(*args, **kwargs)
def has_plan(self, plan):
if not self.paid: # We can't have any plans if we haven't paid
return False
plan_list = [plan.name for plan in self.plans.all()]
return plan in plan_list
class Session(models.Model):
email = models.EmailField()
session = models.CharField(max_length=255)
user = models.ForeignKey(User, on_delete=models.CASCADE)
request = models.CharField(max_length=255, null=True, blank=True)
session = models.CharField(max_length=255, null=True, blank=True)
subscription_id = models.CharField(max_length=255, null=True, blank=True)
plan = models.ForeignKey(Plan, null=True, blank=True, on_delete=models.CASCADE)