aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments/models.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-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,