from datetime import datetime from typing import Optional from pydantic import BaseModel, Field, constr class TodoBase(BaseModel): title: constr(min_length=1, max_length=100) = Field(..., description="The title of the todo item") description: Optional[constr(max_length=500)] = Field(None, description="A detailed description of the todo item") completed: bool = Field(False, description="Whether the todo item is completed") class TodoCreate(TodoBase): pass class TodoUpdate(BaseModel): title: Optional[constr(min_length=1, max_length=100)] = Field(None, description="The title of the todo item") description: Optional[constr(max_length=500)] = Field(None, description="A detailed description of the todo item") completed: Optional[bool] = Field(None, description="Whether the todo item is completed") class TodoInDBBase(TodoBase): id: int = Field(..., description="The unique identifier of the todo item") created_at: datetime = Field(..., description="When the todo item was created") updated_at: datetime = Field(..., description="When the todo item was last updated") class Config: from_attributes = True class Todo(TodoInDBBase): pass class TodoInDB(TodoInDBBase): pass