-
-
Save devtosxn/f41c07518aa54fbbf53c69858cd5cbee to your computer and use it in GitHub Desktop.
concurrency-code-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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