2025-05-17 02:34:44 +00:00

30 lines
760 B
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
# Shared properties
class TodoBase(BaseModel):
title: str = Field(..., min_length=1, max_length=100)
description: Optional[str] = None
completed: bool = False
# Properties to receive via API on creation
class TodoCreate(TodoBase):
pass
# Properties to receive via API on update
class TodoUpdate(BaseModel):
title: Optional[str] = Field(None, min_length=1, max_length=100)
description: Optional[str] = None
completed: Optional[bool] = None
# Properties to return via API
class Todo(TodoBase):
id: int
created_at: datetime
updated_at: datetime
class Config:
orm_mode = True
from_attributes = True