vinindkoeb/app/models/wine_offering.py
carsten d2abe70333 Define core domain models and add first Alembic migration
Nine SQLModel table models covering the Organization/Route hierarchy
(WineCategory, Organization, User, Route, Participant, PurchaseRound,
WineOffering, Order, OrderLine), with explicit tablenames, FK cascade
behavior, and a CHECK constraint preventing a PurchaseRound from
reaching open/closed status without its opens_at/order_deadline_at/
pickup_at dates set. Also fixes the Alembic script template to import
sqlmodel (needed for autogenerate's AutoString column type).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 18:51:04 +02:00

27 lines
1 KiB
Python

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")