53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import ForeignKey, Unicode, 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 .food_table import FoodTable
|
|
from .guest_book import GuestBook
|
|
from .voucher import Voucher
|
|
|
|
|
|
@reg.mapped_as_dataclass(unsafe_hash=True)
|
|
class Overview:
|
|
__tablename__ = "overview"
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4
|
|
)
|
|
voucher_id: Mapped[uuid.UUID] = mapped_column(
|
|
"voucher_id",
|
|
UUID(as_uuid=True),
|
|
ForeignKey("vouchers.id"),
|
|
nullable=False,
|
|
unique=True,
|
|
)
|
|
food_table_id: Mapped[uuid.UUID] = mapped_column(
|
|
"food_table_id",
|
|
UUID(as_uuid=True),
|
|
ForeignKey("food_tables.id"),
|
|
nullable=False,
|
|
unique=True,
|
|
)
|
|
guest_book_id: Mapped[uuid.UUID] = mapped_column(
|
|
"guest_book_id", UUID(as_uuid=True), ForeignKey("guest_book.id"), unique=True, nullable=True
|
|
)
|
|
status: Mapped[str] = mapped_column("status", Unicode(255), nullable=False)
|
|
|
|
voucher: Mapped["Voucher"] = relationship("Voucher", back_populates="status")
|
|
food_table: Mapped["FoodTable"] = relationship("FoodTable", back_populates="status")
|
|
guest: Mapped["GuestBook"] = relationship("GuestBook", back_populates="status")
|
|
|
|
def __init__(self, voucher_id, food_table_id, guest_book_id, status, id_=None):
|
|
self.voucher_id = voucher_id
|
|
self.food_table_id = food_table_id
|
|
self.guest_book_id = guest_book_id
|
|
self.status = status
|
|
self.id = id_
|