From 8a13e1543334f86803cd9909ba3fa5d4619074c0 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 14 Sep 2024 20:20:48 +0100 Subject: wip: testing adding resources to shopping cart --- pyblackbird_cc/payments/models.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pyblackbird_cc/payments/models.py') 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, -- cgit v1.2.3