vinindkoeb/app/models/order_line.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

24 lines
851 B
Python

from typing import TYPE_CHECKING, Optional
from sqlalchemy import CheckConstraint
from sqlmodel import Field, Relationship, SQLModel
if TYPE_CHECKING:
from app.models.order import Order
from app.models.wine_offering import WineOffering
class OrderLineBase(SQLModel):
quantity: int = Field(gt=0)
class OrderLine(OrderLineBase, table=True):
__tablename__ = "order_line"
__table_args__ = (CheckConstraint("quantity > 0", name="ck_order_line_quantity_positive"),)
id: Optional[int] = Field(default=None, primary_key=True)
order_id: int = Field(foreign_key="orders.id", ondelete="CASCADE")
wine_offering_id: int = Field(foreign_key="wine_offering.id", ondelete="RESTRICT")
order: "Order" = Relationship(back_populates="order_lines")
wine_offering: "WineOffering" = Relationship(back_populates="order_lines")