from datetime import datetime, timedelta from typing import Optional from sqlmodel import SQLModel, Field class ProjectBase(SQLModel): """Superclass model which all project classes have in common.""" name: str # = Field(description="Name of the project", example="Learning") class ProjectCreate(ProjectBase): """Model used when a user creates a new project.""" pass class Project(ProjectBase, table=True): """Model used inside the database.""" id: Optional[int] = Field(default=None, primary_key=True) class ProjectRead(ProjectCreate): """Model used when querying information about a module.""" id: int name: str # = Field(description="Name of the project", example="Learning") start_date: datetime # = Field(description="Project creation date", example=datetime.now()) duration: timedelta # = Field(description="Total tracked duration", example=timedelta(days=3, hours=5, minutes=47)) records: int # = Field(description="Total number of trackings/records", example=42) # class Config: # TODO: Adding this config may be done with a decorator # """pydantic config""" # json_encoders = { # # Serialize timedeltas as ISO 8601 and not as float seconds, which is the default # timedelta: timedelta_isoformat, # }