Restoroo/core/models/reservation.py
Kumi 7b5c113f82
Basic reservation implementation
Static file storage
MySQL databases
2022-08-05 15:24:06 +00:00

57 lines
No EOL
2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
from django.utils.translation import gettext as _
from .profiles import Profile
from phonenumber_field.modelfields import PhoneNumberField
class Guest(models.Model):
"""Class representing a guest for a reservation
Could also be used to link other people to a reservation
(think keeping data on the guest's guests, for contact tracing...)
All data in here is optional both for (eventual) GDPR compliance
and because different restaurants might request different information
"""
user_profile = models.ForeignKey(Profile, models.SET_NULL, null=True)
first_name = models.CharField(max_length=128, null=True, blank=True)
last_name = models.CharField(max_length=128, null=True, blank=True)
email = models.EmailField(null=True, blank=True)
phone = PhoneNumberField(null=True, blank=True)
class Reservation(models.Model):
"""Class representing a table reservation
Includes just the basic information on the reservation (number of people,
date, time, stuff like that) personal data is stored in the Guest model
"""
class ReservationStatusChoices(models.IntegerChoices):
"""Class defining options for the status of a reservation
"""
UNCONFIRMED = (0, _("Unconfirmed"))
CONFIRMED = (1, _("Confirmed"))
CANCELLED_BY_GUEST = (-1, _("Cancelled by guest"))
CANCELLED_BY_RESTAURANT = (-2, _("Cancelled by restaurant"))
booker = models.ForeignKey(Guest, models.PROTECT)
datetime = models.DateTimeField()
persons = models.PositiveSmallIntegerField()
status = models.IntegerField(choices=ReservationStatusChoices.choices)
created_at = models.DateTimeField(auto_now_add=True)
@property
def cancelled(self) -> bool:
"""Exposes the status of a Reservation as a boolean value
A negative integer value of Reservation.status will be considered a
cancelled Reservation
Returns:
bool: True if the Reservation is in a cancelled state, else False
"""
return status < 0