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

26 lines
777 B
Python

from typing import TYPE_CHECKING, List, Optional
from sqlmodel import Field, Relationship, SQLModel
if TYPE_CHECKING:
from app.models.order import Order
from app.models.route import Route
class ParticipantBase(SQLModel):
name: str
email: str
phone: Optional[str] = Field(default=None)
is_active: bool = Field(default=True)
class Participant(ParticipantBase, table=True):
__tablename__ = "participant"
id: Optional[int] = Field(default=None, primary_key=True)
route_id: int = Field(foreign_key="route.id", ondelete="CASCADE")
route: "Route" = Relationship(back_populates="participants")
orders: List["Order"] = Relationship(
back_populates="participant", sa_relationship_kwargs={"cascade": "all, delete-orphan"}
)