42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import uuid
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, text
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from ..db.base_class import reg
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from .customer import Customer
|
|
from .overview import Overview
|
|
|
|
|
|
@reg.mapped_as_dataclass(unsafe_hash=True)
|
|
class GuestBook:
|
|
__tablename__ = "guest_book"
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4
|
|
)
|
|
customer_id: Mapped[uuid.UUID] = mapped_column(
|
|
"customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False
|
|
)
|
|
pax: Mapped[int] = mapped_column("pax", Integer, nullable=False)
|
|
date: Mapped[datetime] = mapped_column("creation_date", DateTime(), nullable=False)
|
|
|
|
customer: Mapped["Customer"] = relationship("Customer")
|
|
status: Mapped[Optional["Overview"]] = relationship(back_populates="guest", uselist=False)
|
|
|
|
def __init__(self, pax=None, id_=None, customer_id=None, customer=None, date_=None):
|
|
self.customer_id = customer_id
|
|
self.pax = pax
|
|
self.id = id_
|
|
self.date = datetime.utcnow() if date_ is None else date_
|
|
if customer is None:
|
|
self.customer_id = customer_id
|
|
else:
|
|
self.customer = customer
|