Spaces:
Sleeping
Sleeping
| from sqlmodel import SQLModel, Field, Relationship | |
| from typing import Optional | |
| from datetime import datetime | |
| import uuid | |
| from sqlalchemy import Column, DateTime | |
| class TaskBase(SQLModel): | |
| title: str = Field(min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| completed: bool = Field(default=False) | |
| due_date: Optional[datetime] = None | |
| is_ai_generated: bool = Field(default=False) | |
| class Task(TaskBase, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| user_id: uuid.UUID = Field(foreign_key="user.id", index=True) | |
| project_id: Optional[uuid.UUID] = Field(default=None, foreign_key="project.id", index=True) | |
| title: str = Field(min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| completed: bool = Field(default=False) | |
| due_date: Optional[datetime] = None | |
| created_at: datetime = Field(sa_column=Column(DateTime, default=datetime.utcnow)) | |
| updated_at: datetime = Field(sa_column=Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)) | |
| # Relationship to user | |
| owner: Optional["User"] = Relationship(back_populates="tasks") | |
| # Relationship to project | |
| project: Optional["Project"] = Relationship(back_populates="tasks") | |
| class TaskCreate(TaskBase): | |
| project_id: Optional[uuid.UUID] = None | |
| is_ai_generated: bool = False | |
| class TaskRead(TaskBase): | |
| id: int | |
| user_id: uuid.UUID | |
| project_id: Optional[uuid.UUID] = None | |
| created_at: datetime | |
| updated_at: datetime | |
| is_ai_generated: bool = False | |
| class Config: | |
| from_attributes = True | |
| class TaskUpdate(SQLModel): | |
| title: Optional[str] = Field(default=None, min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| completed: Optional[bool] = None | |
| project_id: Optional[uuid.UUID] = None | |
| due_date: Optional[datetime] = None | |
| is_ai_generated: Optional[bool] = None |