from decimal import Decimal from typing import TYPE_CHECKING, List, Optional from sqlmodel import Field, Relationship, SQLModel if TYPE_CHECKING: from app.models.order_line import OrderLine from app.models.purchase_round import PurchaseRound from app.models.wine_category import WineCategory class WineOfferingBase(SQLModel): name: str price: Decimal = Field(max_digits=10, decimal_places=2) is_organic: bool = Field(default=False) class WineOffering(WineOfferingBase, table=True): __tablename__ = "wine_offering" id: Optional[int] = Field(default=None, primary_key=True) purchase_round_id: int = Field(foreign_key="purchase_round.id", ondelete="CASCADE") category_id: int = Field(foreign_key="wine_category.id", ondelete="RESTRICT") purchase_round: "PurchaseRound" = Relationship(back_populates="wine_offerings") category: "WineCategory" = Relationship(back_populates="wine_offerings") order_lines: List["OrderLine"] = Relationship(back_populates="wine_offering")