41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from typing import Optional
|
|||
|
|
from pydantic import BaseModel, ConfigDict, Field
|
||
|
|
|
||
|
|
# 新增顾问信息
|
||
|
|
class AdvisorCreate(BaseModel):
|
||
|
|
advisor_no: str = Field(description="顾问编号")
|
||
|
|
name: str = Field(description="顾问姓名")
|
||
|
|
gender: Optional[str] = Field(description="顾问性别")
|
||
|
|
phone: Optional[str] = Field(None, description="联系电话")
|
||
|
|
remark: Optional[str] = Field(None, description="备注")
|
||
|
|
|
||
|
|
|
||
|
|
# 修改顾问信息
|
||
|
|
class AdvisorUpdate(BaseModel):
|
||
|
|
name: Optional[str] = Field(None, description="顾问姓名")
|
||
|
|
gender: Optional[str] = Field(None, description="顾问性别")
|
||
|
|
phone: Optional[str] = Field(None, description="联系电话")
|
||
|
|
remark: Optional[str] = Field(None, description="备注")
|
||
|
|
|
||
|
|
# 顾问信息响应体
|
||
|
|
class AdvisorResp(BaseModel):
|
||
|
|
id: int
|
||
|
|
advisor_no: str
|
||
|
|
name: str
|
||
|
|
gender: str
|
||
|
|
phone: Optional[str] = None
|
||
|
|
remark: Optional[str] = None
|
||
|
|
|
||
|
|
# Pydantic v2 写法:允许直接从 ORM 对象取值
|
||
|
|
model_config = ConfigDict(from_attributes=True)
|
||
|
|
|
||
|
|
|
||
|
|
# 某个顾问名下的学生信息
|
||
|
|
class AdvisorStudentResp(BaseModel):
|
||
|
|
id: int = Field(description="学生ID")
|
||
|
|
name: str = Field(description="学生姓名")
|
||
|
|
class_id: Optional[int] = Field(None, description="班级ID")
|
||
|
|
advisor_no: Optional[str] = Field(None, description="顾问编号")
|
||
|
|
|
||
|
|
model_config = ConfigDict(from_attributes=True)
|