You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.2 KiB
56 lines
2.2 KiB
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from sqlalchemy import ForeignKey, Index, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import BaseModel, ID_TYPE, TimestampMixin
|
|
|
|
|
|
class HouseholdMember(BaseModel, TimestampMixin):
|
|
__tablename__ = "household_members"
|
|
__table_args__ = (
|
|
Index("idx_household_members_household_id", "household_id"),
|
|
Index("idx_household_members_household_sort", "household_id", "sort_order"),
|
|
Index("idx_household_members_household_name", "household_id", "name"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(ID_TYPE, primary_key=True)
|
|
household_id: Mapped[int] = mapped_column(
|
|
ID_TYPE,
|
|
ForeignKey("households.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
)
|
|
name: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
relation_to_head: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
gender: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
|
age_group: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
|
is_child: Mapped[bool] = mapped_column(nullable=False, default=False)
|
|
needs_red_packet: Mapped[bool] = mapped_column(nullable=False, default=False)
|
|
expected_to_attend: Mapped[bool] = mapped_column(nullable=False, default=True)
|
|
actually_attended: Mapped[bool] = mapped_column(nullable=False, default=False)
|
|
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
created_by: Mapped[int | None] = mapped_column(
|
|
ID_TYPE,
|
|
ForeignKey("accounts.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
)
|
|
updated_by: Mapped[int | None] = mapped_column(
|
|
ID_TYPE,
|
|
ForeignKey("accounts.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
)
|
|
|
|
household: Mapped[Any] = relationship("Household", back_populates="members")
|
|
created_by_account: Mapped[Any] = relationship(
|
|
"Account",
|
|
foreign_keys=[created_by],
|
|
back_populates="created_members",
|
|
)
|
|
updated_by_account: Mapped[Any] = relationship(
|
|
"Account",
|
|
foreign_keys=[updated_by],
|
|
back_populates="updated_members",
|
|
)
|
|
|