mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Any, Optional
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator, validator
|
|
|
|
from app.core.base_schema import BaseSchema
|
|
from app.core.validator import DateTimeStr
|
|
from app.core.logger import logger
|
|
|
|
class DeptCreateSchema(BaseModel):
|
|
"""部门创建模型"""
|
|
name: str = Field(..., max_length=40, description="部门名称")
|
|
order: int = Field(default=1, ge=0, description="显示顺序")
|
|
available: bool = Field(default=True, description="是否启用(True:启用 False:禁用)")
|
|
parent_id: Optional[int] = Field(default=None, ge=0, description="父部门ID")
|
|
description: Optional[str] = Field(default=None, max_length=500, description="备注说明")
|
|
|
|
@model_validator(mode='after')
|
|
def validate_fields(self):
|
|
if not self.name or len(self.name.strip()) == 0:
|
|
raise ValueError("部门名称不能为空")
|
|
self.name = self.name.replace(" ", "")
|
|
return self
|
|
|
|
|
|
class DeptUpdateSchema(DeptCreateSchema):
|
|
"""部门更新模型"""
|
|
id: int = Field(..., gt=0, description="部门ID")
|
|
|
|
|
|
class DeptOutSchema(DeptCreateSchema, BaseSchema):
|
|
"""部门响应模型"""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
parent_name: Optional[str] = Field(default=None, max_length=40, description="父部门名称")
|