45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
"""Base schema for Item."""
|
|
|
|
name: str = Field(..., min_length=1, max_length=255, description="Name of the item")
|
|
description: Optional[str] = Field(None, description="Description of the item")
|
|
is_active: bool = Field(True, description="Whether the item is active")
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
"""Schema for creating a new Item."""
|
|
pass
|
|
|
|
|
|
class ItemUpdate(BaseModel):
|
|
"""Schema for updating an Item."""
|
|
|
|
name: Optional[str] = Field(None, min_length=1, max_length=255, description="Name of the item")
|
|
description: Optional[str] = Field(None, description="Description of the item")
|
|
is_active: Optional[bool] = Field(None, description="Whether the item is active")
|
|
|
|
|
|
class ItemInDBBase(ItemBase):
|
|
"""Base schema for Item in DB."""
|
|
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Item(ItemInDBBase):
|
|
"""Schema for Item with all fields."""
|
|
pass
|
|
|
|
|
|
class ItemInDB(ItemInDBBase):
|
|
"""Schema for Item in DB (internal use)."""
|
|
pass |