2025-05-17 22:13:56 +00:00

38 lines
965 B
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
# Base schema for Todo
class TodoBase(BaseModel):
"""Base schema for Todo items."""
title: str = Field(..., min_length=1, max_length=100)
description: Optional[str] = Field(None, max_length=500)
completed: bool = False
# Schema for creating a new Todo
class TodoCreate(TodoBase):
"""Schema for creating a new Todo."""
pass
# Schema for updating a Todo
class TodoUpdate(BaseModel):
"""Schema for updating a Todo."""
title: Optional[str] = Field(None, min_length=1, max_length=100)
description: Optional[str] = Field(None, max_length=500)
completed: Optional[bool] = None
# Schema for Todo in response
class TodoResponse(TodoBase):
"""Schema for Todo in response."""
id: int
created_at: datetime
updated_at: datetime
class Config:
"""Pydantic config for Todo."""
from_attributes = True