Spaces:
Sleeping
Sleeping
Download src/models/todo.py from hashir-qt/tasklert-api: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/src/models/todo.py
- Command line
-
hf download hf://spaces/hashir-qt/tasklert-api/src/models/todo.py
-
curl -L -o todo.py https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/src/models/todo.py
3 kB
| from datetime import datetime | |
| from typing import Optional | |
| from pydantic import field_validator | |
| from sqlalchemy import ARRAY, String | |
| from sqlmodel import Column, Field, SQLModel | |
| class Todo(SQLModel, table=True): | |
| id: int | None = Field(default=None, primary_key=True) | |
| title: str = Field(index=True) | |
| description: str | None = Field(default=None) | |
| completed: bool = False | |
| user_id: str = Field(foreign_key="user.id", index=True) # UUID string to match Better Auth | |
| created_at: datetime = Field( | |
| default_factory=datetime.utcnow # Timezone-naive for PostgreSQL TIMESTAMP | |
| ) | |
| updated_at: datetime = Field( | |
| default_factory=datetime.utcnow # Timezone-naive for PostgreSQL TIMESTAMP | |
| ) | |
| # --- Phase V fields --- | |
| priority: str = Field(default="medium") # high | medium | low | |
| tags: list[str] = Field(default_factory=list, sa_column=Column(ARRAY(String))) | |
| due_date: datetime | None = Field(default=None) | |
| reminder_at: datetime | None = Field(default=None) | |
| recurrence: str = Field(default="none") # none | daily | weekly | monthly | |
| parent_id: int | None = Field(default=None, foreign_key="todo.id") | |
| class TodoCreate(SQLModel): | |
| title: str | |
| description: str | None = None | |
| priority: str = "medium" | |
| tags: list[str] = Field(default_factory=list) | |
| due_date: datetime | None = None | |
| reminder_at: datetime | None = None | |
| recurrence: str = "none" | |
| def title_length(cls, v: str) -> str: | |
| if not v or len(v) > 200: | |
| raise ValueError("Title must be 1-200 characters") | |
| return v | |
| def description_length(cls, v: str | None) -> str | None: | |
| if v is not None and len(v) > 1000: | |
| raise ValueError("Description must be 1000 characters or fewer") | |
| return v | |
| def priority_valid(cls, v: str) -> str: | |
| if v not in ("high", "medium", "low"): | |
| raise ValueError("Priority must be high, medium, or low") | |
| return v | |
| def recurrence_valid(cls, v: str) -> str: | |
| if v not in ("none", "daily", "weekly", "monthly"): | |
| raise ValueError("Recurrence must be none, daily, weekly, or monthly") | |
| return v | |
| class TodoUpdate(SQLModel): | |
| title: str | None = None | |
| description: str | None = None | |
| completed: bool | None = None | |
| priority: str | None = None | |
| tags: list[str] | None = None | |
| due_date: Optional[datetime] = None | |
| reminder_at: Optional[datetime] = None | |
| recurrence: str | None = None | |
| class TodoRead(SQLModel): | |
| id: int | |
| title: str | |
| description: str | None | |
| completed: bool | |
| user_id: str | |
| priority: str | |
| tags: list[str] | |
| due_date: datetime | None | |
| reminder_at: datetime | None | |
| recurrence: str | |
| parent_id: int | None | |
| created_at: datetime | |
| updated_at: datetime | |