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
@classmethod | |
def book(cls, id, seats_selected): | |
with transaction.atomic(): | |
if seats < self.seats_selected: | |
raise errors.InsufficientSeats() | |
slot = (cls.objects.select_for_update().get(id=id)) | |
slot.seats -= seats_selected | |
slot.save() | |
return slot |
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
@classmethod | |
def cancel(cls, id, seats_selected): | |
with transaction.atomic(): | |
slot= (cls.objects.select_for_update().get(id=id)) | |
slot.seats += seats_selected | |
slot.save() | |
return slot |
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
def book(self, seats_selected,slot_id): | |
if self.seats < self.seats_selected: | |
raise errors.InsufficientSeats() | |
self.seats -= seats_selected | |
self.save() | |
def cancel_booking(self, seats_selected): | |
self.seats += seats_selected | |
self.save() |
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
class Slot(models.Model): | |
id = models.AutoField(primary_key=True,) | |
user = models.ForeignKey(User) | |
seats= models.IntegerField(default=10) |