40 lines
946 B
Python
40 lines
946 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=255)
|
|
description: Optional[str] = None
|
|
completed: bool = False
|
|
priority: int = Field(0, ge=0, le=2) # 0=low, 1=medium, 2=high
|
|
|
|
|
|
# Properties to receive on item creation
|
|
class TodoCreate(TodoBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive on item update
|
|
class TodoUpdate(BaseModel):
|
|
title: Optional[str] = Field(None, min_length=1, max_length=255)
|
|
description: Optional[str] = None
|
|
completed: Optional[bool] = None
|
|
priority: Optional[int] = Field(None, ge=0, le=2)
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class TodoInDBBase(TodoBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Todo(TodoInDBBase):
|
|
pass |