| from sqlmodel import Field, SQLModel, Relationship |
| from typing import Optional, TYPE_CHECKING |
| from datetime import datetime |
|
|
| if TYPE_CHECKING: |
| from .user import User |
|
|
|
|
| class Task(SQLModel, table=True): |
| """Task model representing a todo item belonging to a specific user.""" |
|
|
| __tablename__ = "tasks" |
|
|
| id: Optional[int] = Field(default=None, primary_key=True) |
| title: str = Field(max_length=200, min_length=1) |
| description: Optional[str] = Field(default=None, max_length=2000) |
| completed: bool = Field(default=False) |
| user_id: int = Field(foreign_key="users.id", index=True) |
| created_at: datetime = Field(default_factory=datetime.utcnow) |
| updated_at: datetime = Field(default_factory=datetime.utcnow) |
|
|
| |
| owner: "User" = Relationship(back_populates="tasks") |
|
|