2022-07-21 12:45:44 +00:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
2022-07-21 12:45:57 +00:00
|
|
|
class Plan(models.Model):
|
|
|
|
name = models.CharField(max_length=255, unique=True)
|
|
|
|
description = models.CharField(max_length=1024, null=True, blank=True)
|
2022-07-21 12:45:44 +00:00
|
|
|
cost = models.IntegerField()
|
2022-07-21 12:45:57 +00:00
|
|
|
product_id = models.UUIDField(null=True, blank=True)
|
|
|
|
image = models.CharField(max_length=1024, null=True, blank=True)
|
2022-07-21 12:45:44 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.name} (£{self.cost})"
|
|
|
|
|
|
|
|
|
|
|
|
class User(AbstractUser):
|
|
|
|
# Stripe customer ID
|
2022-07-21 12:45:57 +00:00
|
|
|
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)
|
2022-07-21 12:45:44 +00:00
|
|
|
|
|
|
|
def has_plan(self, plan):
|
2022-07-21 12:46:48 +00:00
|
|
|
if not self.paid: # We can't have any plans if we haven't paid
|
|
|
|
return False
|
2022-07-21 12:45:44 +00:00
|
|
|
plan_list = [plan.name for plan in self.plans.all()]
|
|
|
|
return plan in plan_list
|