aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-14 20:20:48 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-14 20:20:48 +0100
commit8a13e1543334f86803cd9909ba3fa5d4619074c0 (patch)
tree05498d5ddc76840d8168c98b979e21d854d25efa /pyblackbird_cc/payments/models.py
parentf312ec6d4a577e71d76cf85632a198b0c1913703 (diff)
wip: testing adding resources to shopping cart
Diffstat (limited to 'pyblackbird_cc/payments/models.py')
-rw-r--r--pyblackbird_cc/payments/models.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py
index 81bb1c8..b947a22 100644
--- a/pyblackbird_cc/payments/models.py
+++ b/pyblackbird_cc/payments/models.py
@@ -1,4 +1,5 @@
from django.conf import settings
+from django.core.exceptions import ValidationError
from django.db import models
from pyblackbird_cc.resources.models import Resource
@@ -27,6 +28,8 @@ class ShoppingCart(models.Model):
return f"Shopping Cart for {self.user.username}"
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,