Spaces:
Sleeping
Sleeping
File size: 1,740 Bytes
ca76540 | 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 | from sqlmodel import SQLModel, Field, Relationship
from typing import Optional
import uuid
from datetime import datetime
from .user import User
class TaskBase(SQLModel):
title: str = Field(sa_column_kwargs={"nullable": False})
description: Optional[str] = Field(default=None)
completed: bool = Field(default=False)
user_id: uuid.UUID = Field(foreign_key="users.id")
category: str = Field(default="")
due_date: Optional[datetime] = Field(default=None)
class Task(TaskBase, table=True):
"""
Task model representing a todo item owned by a specific user.
"""
__tablename__ = "tasks"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default_factory=datetime.utcnow)
# Relationship to User - commented out to prevent circular import during initialization
# user: User = Relationship(back_populates="tasks")
class Config:
arbitrary_types_allowed = True
class TaskCreate(SQLModel):
"""
Schema for creating a new task.
"""
title: str
description: Optional[str] = None
completed: bool = False
category: str = ""
due_date: Optional[datetime] = None
# user_id is not included as it comes from JWT token
class TaskUpdate(SQLModel):
"""
Schema for updating an existing task.
"""
title: Optional[str] = None
description: Optional[str] = None
completed: Optional[bool] = None
category: Optional[str] = None
due_date: Optional[datetime] = None
class TaskRead(TaskBase):
"""
Schema for reading task information.
"""
id: uuid.UUID
created_at: datetime
updated_at: datetime |