43 lines
785 B
Python
43 lines
785 B
Python
"""
|
|
博客文章相关的 Pydantic 模式
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class PostBase(BaseModel):
|
|
"""博客文章基础模式"""
|
|
title: str
|
|
slug: str
|
|
content: str
|
|
|
|
|
|
class PostCreate(PostBase):
|
|
"""创建博客文章请求模式"""
|
|
pass
|
|
|
|
|
|
class PostUpdate(BaseModel):
|
|
"""更新博客文章请求模式"""
|
|
title: Optional[str] = None
|
|
slug: Optional[str] = None
|
|
content: Optional[str] = None
|
|
|
|
|
|
class PostInDB(PostBase):
|
|
"""数据库中的博客文章模式"""
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
user_id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Post(PostInDB):
|
|
"""博客文章响应模式"""
|
|
pass
|
|
|