Spaces:
Sleeping
Sleeping
| from sqlmodel import SQLModel, Field, Relationship | |
| from typing import Optional, List | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Column, DateTime | |
| class ProjectBase(SQLModel): | |
| name: str = Field(min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| color: Optional[str] = Field(default="#3b82f6", max_length=7) # Hex color code | |
| class Project(ProjectBase, table=True): | |
| id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4, primary_key=True) | |
| user_id: uuid.UUID = Field(foreign_key="user.id", index=True) | |
| name: str = Field(min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| color: Optional[str] = Field(default="#3b82f6", max_length=7) | |
| 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)) | |
| deadline: Optional[datetime] = None | |
| # Relationship to user | |
| owner: Optional["User"] = Relationship(back_populates="projects") | |
| # Relationship to tasks | |
| tasks: List["Task"] = Relationship(back_populates="project") | |
| class ProjectCreate(ProjectBase): | |
| pass | |
| class ProjectRead(ProjectBase): | |
| id: uuid.UUID | |
| user_id: uuid.UUID | |
| created_at: datetime | |
| updated_at: datetime | |
| class Config: | |
| from_attributes = True | |
| class ProjectUpdate(SQLModel): | |
| name: Optional[str] = Field(default=None, min_length=1, max_length=200) | |
| description: Optional[str] = Field(default=None, max_length=1000) | |
| color: Optional[str] = Field(default=None, max_length=7) | |
| deadline: Optional[datetime] = None |