Spaces:
Sleeping

todo-project / src /models /task.py
bhaimavi353's picture
Upload folder using huggingface_hub
b3943f2 verified
Raw History Blame Contribute Delete
1.25 kB
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from sqlmodel import SQLModel, Field, Relationship
if TYPE_CHECKING:
from .user import User
class TaskBase(SQLModel):
title: str = Field(max_length=255)
description: Optional[str] = Field(default=None, max_length=1000)
completed: bool = Field(default=False)
class Task(TaskBase, table=True):
__tablename__ = "tasks"
id: Optional[int] = Field(default=None, primary_key=True)
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)
user: Optional["User"] = Relationship(back_populates="tasks")
class TaskCreate(SQLModel):
title: str = Field(max_length=255)
description: Optional[str] = Field(default=None, max_length=1000)
class TaskRead(SQLModel):
id: int
title: str
description: Optional[str]
completed: bool
created_at: datetime
updated_at: datetime
user_id: int
class TaskUpdate(SQLModel):
title: Optional[str] = Field(default=None, max_length=255)
description: Optional[str] = Field(default=None, max_length=1000)
completed: Optional[bool] = None