new checker for remaining tickets
This commit is contained in:
parent
d95b003e56
commit
57792b908d
@ -64,6 +64,9 @@ class Product(models.Model):
|
||||
price = models.IntegerField()
|
||||
quantity = models.IntegerField()
|
||||
|
||||
def __str__(self):
|
||||
f"<Product {self.name} {self.price} Kč zbývá {self.quantity}>"
|
||||
|
||||
|
||||
class Cart(models.Model):
|
||||
user = models.ForeignKey(DjangoUser, on_delete=models.RESTRICT)
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user