Files
2026-09-14 11:51:13 +08:00

43 lines
1.2 KiB
Python

#老师表请求体模型
from typing import Optional
from pydantic import Field, BaseModel, field_validator
#添加教师信息请求体
class TeacherAdd(BaseModel):
name : str = Field(..., max_length=50,description="姓名")
phone : str = Field(..., description="手机号")
type : str = Field(..., max_length=50, description="教师类型")
# 校验器 输入手机号必须为11位
@field_validator("phone")
@classmethod #类方法
def phone_length(cls, v:str):
if len(v) != 11:
raise ValueError('手机号必须为11位')
return v
class TeacherUpdate(BaseModel):
name: Optional[str] = Field(None,max_length=50, description="姓名")
phone: Optional[str] = Field(None,description="手机号")
type: Optional[str] = Field(None,max_length=50, description="教师类型")
#校验器 输入手机号必须为11位
@field_validator("phone")
@classmethod #类方法
def phone_length(cls, v: Optional[str]):
if v is not None and len(v) != 11:
raise ValueError('手机号必须为11位')
return v
#教师响应体模型
class TeacherResponse(BaseModel):
id: str
name: str
phone: str
type: str