54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
"""项目分类 Schema"""
|
|
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class CategoryBase(BaseModel):
|
|
"""分类基础字段"""
|
|
|
|
category_name: str = Field(..., min_length=1, max_length=50, description="分类名称")
|
|
parent_id: Optional[int] = Field(None, description="父分类ID")
|
|
sort_order: int = Field(0, ge=0, description="排序")
|
|
is_active: bool = Field(True, description="是否启用")
|
|
|
|
|
|
class CategoryCreate(CategoryBase):
|
|
"""创建分类请求"""
|
|
pass
|
|
|
|
|
|
class CategoryUpdate(BaseModel):
|
|
"""更新分类请求"""
|
|
|
|
category_name: Optional[str] = Field(None, min_length=1, max_length=50, description="分类名称")
|
|
parent_id: Optional[int] = Field(None, description="父分类ID")
|
|
sort_order: Optional[int] = Field(None, ge=0, description="排序")
|
|
is_active: Optional[bool] = Field(None, description="是否启用")
|
|
|
|
|
|
class CategoryResponse(CategoryBase):
|
|
"""分类响应"""
|
|
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class CategoryTreeResponse(CategoryResponse):
|
|
"""分类树形响应"""
|
|
|
|
children: List["CategoryTreeResponse"] = []
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# 解决循环引用
|
|
CategoryTreeResponse.model_rebuild()
|