Team Ai
Apppublic

ruby2210/todo-manager

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
task.py49 linesDownload Raw Back to models
1from sqlmodel import SQLModel, Field, Column2from typing import Optional3from datetime import datetime4import uuid5 6 7class TaskBase(SQLModel):8    title: str = Field(min_length=1, max_length=255)9    description: Optional[str] = Field(default=None, max_length=1000)10    completed: bool = Field(default=False)11    user_id: str = Field(index=True)  # Foreign key to users table (managed by Better Auth)12 13 14class Task(TaskBase, table=True):15    """16    Task model representing a user's task with properties:17    - id: Auto-incrementing primary key18    - user_id: Foreign key to users.id from Better Auth19    - title: Task title (required, max 255 chars)20    - description: Task description (optional, max 1000 chars)21    - completed: Task completion status (default: False)22    - created_at: Task creation timestamp (auto-generated)23    - updated_at: Task last update timestamp (auto-generated)24    """25    id: Optional[int] = Field(default=None, primary_key=True)26    created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)27    updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)28 29    # Update updated_at on modification30    def __setattr__(self, name, value):31        if name == "updated_at":32            # Allow explicit setting of updated_at33            super().__setattr__(name, value)34        elif name in ["title", "description", "completed"]:35            # Update updated_at when important fields change36            super().__setattr__("updated_at", datetime.utcnow())37            super().__setattr__(name, value)38        else:39            super().__setattr__(name, value)40 41 42class TaskUpdate(SQLModel):43    title: Optional[str] = Field(default=None, min_length=1, max_length=255)44    description: Optional[str] = Field(default=None, max_length=1000)45    completed: Optional[bool] = Field(default=None)46 47 48class TaskCreate(TaskBase):49    pass  # Inherits all fields from TaskBase