File size: 1,348 Bytes
bc67c7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""

Task model for todo management.

[Task]: T-006 (Task Model)

[From]: spec.md §7.2, plan.md §5

"""

from sqlmodel import SQLModel, Field, Relationship
from uuid import UUID
from datetime import datetime
from typing import Optional, TYPE_CHECKING

if TYPE_CHECKING:
    from src.models.user import User


class Task(SQLModel, table=True):
    """

    Task/Todo item model.

    

    Each task belongs to one user (user_id foreign key).

    """
    __tablename__ = "tasks"
    
    id: Optional[int] = Field(
        default=None,
        primary_key=True,
        nullable=False
    )
    
    user_id: UUID = Field(
        foreign_key="users.id",
        nullable=False,
        index=True
    )
    
    title: str = Field(
        nullable=False,
        min_length=1,
        max_length=200
    )
    
    description: Optional[str] = Field(
        default=None,
        max_length=1000
    )
    
    completed: bool = Field(
        default=False,
        nullable=False
    )
    
    created_at: datetime = Field(
        default_factory=datetime.utcnow,
        nullable=False
    )
    
    updated_at: datetime = Field(
        default_factory=datetime.utcnow,
        nullable=False
    )
    
    # Relationships
    user: "User" = Relationship(back_populates="tasks")