Skip to content

Instantly share code, notes, and snippets.

@devtosxn
Last active February 1, 2024 15:21
Show Gist options
  • Save devtosxn/f41c07518aa54fbbf53c69858cd5cbee to your computer and use it in GitHub Desktop.
Save devtosxn/f41c07518aa54fbbf53c69858cd5cbee to your computer and use it in GitHub Desktop.
concurrency-code-1
# models.py
class Ticket(models.Model):
event = models.CharField(max_length=100)
available_seats = models.IntegerField()
# views.py
def reserve_ticket(request, ticket_id):
ticket = get_object_or_404(Ticket, id=ticket_id)
if ticket.available_seats > 0:
ticket.available_seats -= 1
ticket.save()
# Process reservation
else:
# Handle no available seats
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment