From 57792b908dcc1ed69eb911669cceef5ddcec1ccd Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Sun, 13 Oct 2024 08:15:52 +0200 Subject: [PATCH] new checker for remaining tickets --- alkatorapi/models.py | 3 +++ alkatorapi/views.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/alkatorapi/models.py b/alkatorapi/models.py index ac07add..8093cec 100644 --- a/alkatorapi/models.py +++ b/alkatorapi/models.py @@ -64,6 +64,9 @@ class Product(models.Model): price = models.IntegerField() quantity = models.IntegerField() + def __str__(self): + f"" + class Cart(models.Model): user = models.ForeignKey(DjangoUser, on_delete=models.RESTRICT) diff --git a/alkatorapi/views.py b/alkatorapi/views.py index d298dd9..f5625eb 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -93,8 +93,6 @@ def register_racer(request): return HttpResponse('{"reason":"Jméno je povinné!"}', status=400, content_type='application/json') if not request.POST['last_name']: return HttpResponse('{"reason":"Přijmení je povinné!"}', status=400, content_type='application/json') - if Racer.objects.filter(alkator_class=ALKATOR_CLASS, paid=True).count() >= 100: - return HttpResponse('{"reason":"Kapacita závodu byla naplněna!"}', status=400, content_type='application/json') try: dob = datetime.strptime(request.POST['date_of_birth'], "%Y-%m-%d").date() if dob > date(2006, 10, 5): @@ -122,6 +120,12 @@ def register_racer(request): product = Product.objects.get(id=1) price = product.price + if product.quantity <= 0: + return HttpResponse('{"reason":"Jsme vyprodaní!"}', status=400, content_type='application/json') + + product.quantity -= 1 + product.save() + racer = Racer( product=product, quantity=1,