48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# Shared properties
|
|
class ItemBase(BaseModel):
|
|
title: str = Field(..., min_length=1, max_length=255, example="My Item")
|
|
description: Optional[str] = Field(
|
|
None, example="A detailed description of my item"
|
|
)
|
|
is_active: Optional[bool] = Field(True, example=True)
|
|
|
|
|
|
# Properties to receive on item creation
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive on item update
|
|
class ItemUpdate(BaseModel):
|
|
title: Optional[str] = Field(
|
|
None, min_length=1, max_length=255, example="Updated Item Title"
|
|
)
|
|
description: Optional[str] = Field(None, example="Updated description")
|
|
is_active: Optional[bool] = Field(None, example=True)
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class ItemInDBBase(ItemBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Item(ItemInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties stored in DB
|
|
class ItemInDB(ItemInDBBase):
|
|
pass
|