aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc/payments/models.py')
-rw-r--r--pyblackbird_cc/payments/models.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py
index 174e3fe..81bb1c8 100644
--- a/pyblackbird_cc/payments/models.py
+++ b/pyblackbird_cc/payments/models.py
@@ -26,21 +26,25 @@ class ShoppingCart(models.Model):
def __str__(self):
return f"Shopping Cart for {self.user.username}"
+ def add_resource(self, resource: Resource):
+ 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)
- quantity = models.PositiveIntegerField(default=1)
added_at = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ("cart", "resource")
def __str__(self):
- return f"{self.quantity} of {self.resource.name} in {self.cart.user.username}'s cart"
-
- def get_total_price(self):
- return self.quantity * self.resource.price
+ return f"{self.resource.name} in {self.cart.user.username}'s cart"
class SubscriptionPlan(models.Model):