38 lines
878 B
Python
38 lines
878 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class TodoBase(BaseModel):
|
|
"""Base Todo schema with common attributes"""
|
|
title: str = Field(..., min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
completed: bool = False
|
|
|
|
|
|
class TodoCreate(TodoBase):
|
|
"""Schema for creating a new Todo"""
|
|
pass
|
|
|
|
|
|
class TodoUpdate(BaseModel):
|
|
"""Schema for updating a Todo - all fields are optional"""
|
|
title: Optional[str] = Field(None, min_length=1, max_length=100)
|
|
description: Optional[str] = None
|
|
completed: Optional[bool] = None
|
|
|
|
|
|
class TodoInDB(TodoBase):
|
|
"""Schema for Todo as stored in the database"""
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Todo(TodoInDB):
|
|
"""Schema for Todo responses"""
|
|
pass |