File size: 1,099 Bytes
b93a6a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sqlmodel import SQLModel, Field, Relationship
from datetime import datetime
from typing import Optional

class Subtask(SQLModel, table=True):
    """Subtask model representing a checklist item within a task."""

    __tablename__ = "subtasks"

    id: Optional[int] = Field(default=None, primary_key=True)
    task_id: int = Field(foreign_key="tasks.id", index=True)
    title: str = Field(max_length=500)
    completed: bool = Field(default=False)
    order: int = Field(default=0)  # For ordering subtasks
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)

    # Relationships
    task: "Task" = Relationship(back_populates="subtasks")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "task_id": 42,
                "title": "Review documentation",
                "completed": False,
                "order": 0,
                "created_at": "2026-02-05T10:00:00Z",
                "updated_at": "2026-02-05T10:00:00Z"
            }
        }