2025-05-17 02:53:13 +00:00

38 lines
1.0 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
# Base schema for Todo
class TodoBase(BaseModel):
title: str = Field(
..., title="The title of the todo item", min_length=1, max_length=100
)
description: Optional[str] = Field(None, title="The description of the todo item")
completed: bool = Field(False, title="Whether the todo item is completed")
# Schema for creating a new Todo
class TodoCreate(TodoBase):
pass
# Schema for updating a Todo
class TodoUpdate(BaseModel):
title: Optional[str] = Field(
None, title="The title of the todo item", min_length=1, max_length=100
)
description: Optional[str] = Field(None, title="The description of the todo item")
completed: Optional[bool] = Field(None, title="Whether the todo item is completed")
# Schema for reading Todo information
class TodoResponse(TodoBase):
id: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True