aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-15 21:01:31 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-15 21:01:31 +0100
commiteeaddb27560d723ca7d61359744ceb2709fccd2d (patch)
tree04ddbc49ae7b73d5f5a9e1716d7227aecd3b9f85 /pyblackbird_cc/payments/models.py
parent7a3044c859043837e6c7c95bb4894d04e9b2cbc2 (diff)
Renamed from pyblackbird_cc to alphabetlearning - everywhere
Diffstat (limited to 'pyblackbird_cc/payments/models.py')
-rw-r--r--pyblackbird_cc/payments/models.py71
1 files changed, 0 insertions, 71 deletions
diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py
deleted file mode 100644
index a7cb8a7..0000000
--- a/pyblackbird_cc/payments/models.py
+++ /dev/null
@@ -1,71 +0,0 @@
-from django.conf import settings
-from django.core.exceptions import ValidationError
-from django.db import models
-
-from pyblackbird_cc.resources.models import Resource
-
-
-class Product(models.Model):
- name = models.CharField(max_length=255)
- stripe_product_id = models.CharField(max_length=100)
-
-
-class Price(models.Model):
- product = models.ForeignKey(Product, on_delete=models.CASCADE)
- price = models.IntegerField(default=0)
- stripe_price_id = models.CharField(max_length=100)
-
- def get_display_price(self):
- return "{0:.2f}".format(self.price / 100)
-
-
-class ShoppingCart(models.Model):
- user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
- created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(auto_now=True)
-
- def __str__(self):
- return f"Shopping cart for {self.user.email}"
-
- def add_resource(self, resource: Resource):
- if CartItem.objects.filter(cart=self, resource=resource).exists():
- raise ValidationError(f"{resource.name} is already in your shopping cart.")
- item, created = CartItem.objects.get_or_create(
- cart=self,
- resource=resource,
- )
- if not created:
- item.save()
-
-
-class CartItem(models.Model):
- cart = models.ForeignKey(ShoppingCart, on_delete=models.CASCADE, related_name="items")
- resource = models.ForeignKey(Resource, on_delete=models.CASCADE)
- added_at = models.DateTimeField(auto_now_add=True)
-
- class Meta:
- unique_together = ("cart", "resource")
-
- def __str__(self):
- return f"{self.resource.name} in {self.cart.user.username}'s cart"
-
-
-class SubscriptionPlan(models.Model):
- name = models.CharField(max_length=255)
- price = models.DecimalField(max_digits=6, decimal_places=2)
- description = models.TextField()
- allowed_downloads = models.PositiveIntegerField()
-
-
-class Subscription(models.Model):
- user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
- plan = models.ForeignKey(SubscriptionPlan, on_delete=models.CASCADE)
- is_active = models.BooleanField(default=False)
- 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}"