0

Hello I'm writing a simple app for reserving and buying the tickets in in cinema, one of the task is to reserve a ticket for some time (ex. 1 hour) its then in pending status and can be paid withing this period. Do you have any recommendation how to achieve expiration time? I have a field in Model storing the date that can be used.

1 Answers1

0

One way is to define a property on your model. for example lets say you have a Ticket model which has a datetime field named reservation_date and you want the ticket reservation to be expired after one hour. Your property decorated method would be like this

@property
def is_expired(self):
    seconds_in_hour = 3600
    if (datetime.now() - self.reservation_date).seconds > seconds_in_hour
        return True
    else:
        return False

Then to check if the ticket is expired:

if ticket_instance.is_expired:
    #do something
Mohammad hp
  • 446
  • 4
  • 16