Add subscription functionality

This commit is contained in:
2025-10-08 13:53:03 +02:00
parent 81daf2aa0c
commit 65b2abdad6
4 changed files with 270 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import typing
from datetime import datetime
from xmlrpc.client import DateTime
from sqlmodel import Field, Relationship, SQLModel, String
@@ -79,3 +80,51 @@ class Registration(SQLModel, table=True):
comment: str | None
household: Household = Relationship()
class Subscription(SQLModel, table=True):
household_id: int | None = Field(
default=None, foreign_key="household.id", primary_key=True
)
num_adult_meals: int
num_children_meals: int
num_small_children_meals: int
comment: str | None
last_modified: datetime = Field(default_factory=datetime.now, nullable=False)
monday: bool = True
tuesday: bool = True
wednesday: bool = True
thursday: bool = True
friday: bool = True
saturday: bool = True
sunday: bool = True
household: Household = Relationship()
def day_string_de(self) -> str:
"""
Generates a string representation of selected days in German short form.
"""
result = []
if self.monday:
result.append("Mo")
if self.tuesday:
result.append("Di")
if self.wednesday:
result.append("Mi")
if self.thursday:
result.append("Do")
if self.friday:
result.append("Fr")
if self.saturday:
result.append("Sa")
if self.sunday:
result.append("So")
if len(result) < 7:
return ", ".join(result)
else:
return "Alle"