ixg_platform/apps/subscriptions/models.py

33 lines
1.3 KiB
Python

import uuid
from django.conf import settings
from django.db import models
class Subscription(models.Model):
class Plan(models.TextChoices):
OBSERVER = "observer", "Observer"
STARTER = "starter", "Starter"
PROFESSIONAL = "professional", "Professional"
ENTERPRISE = "enterprise", "Enterprise"
class Status(models.TextChoices):
ACTIVE = "active", "Active"
CANCELLED = "cancelled", "Cancelled"
PAST_DUE = "past_due", "Past Due"
TRIALING = "trialing", "Trialing"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="subscriptions")
plan = models.CharField(max_length=20, choices=Plan.choices)
stripe_subscription_id = models.CharField(max_length=255, unique=True, null=True, blank=True)
stripe_price_id = models.CharField(max_length=255, blank=True)
status = models.CharField(max_length=20, choices=Status.choices, default=Status.TRIALING)
current_period_end = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "subscriptions"
ordering = ["-created_at"]
def __str__(self):
return f"{self.user.email} - {self.plan} ({self.status})"