Files
sss/student_system_final/scheme/students.py
T

60 lines
1.7 KiB
Python
Raw Normal View History

2026-09-21 22:13:04 +08:00
# scheme/students.py
# 本文件定义学生模块用到的 Pydantic 模型(接口的请求参数 / 响应格式)
from typing import Optional,List
from datetime import date
io
from model.classes import Class
# 创建学生的请求体模型
class StudentCreate(BaseModel):
cid: int = Field(..., description="班级编号")
name: str = Field(..., description="姓名")
address: str = Field(..., description="籍贯")
school: str = Field(..., description="毕业院校")
major: str = Field(..., description="专业")
start_time: date = Field(..., description="入学时间")
end_time: Optional[date] = Field(None, description="毕业时间,未毕业可以不传")
education: str = Field(..., description="学历")
consultant_id: int = Field(..., description="顾问编号")
gender: str = Field(...,max_length=1, description="性别,男/女")
age: int = Field(..., description="年龄")
#
# 更新学生的请求体模型
class StudentUpdate(BaseModel):
cid: Optional[int] = None
name: Optional[str] = None
address: Optional[str] = None
# school: Optional[str] = None
# major: Optional[str] = None
# education: Optional[str] = None
# consultant_id: Optional[int] = None
# gender: Optional[str] = None
# age: Optional[int] = None
# 响应模型
class StudentResponse(BaseModel):
sid: int
cid: int
name: str
address: str
school: str
major: str
start_time: date
end_time: Optional[date] = None
education: str
consultant_id: int
gender: str
age: int
flag: int
class Config:
from_attributes = True # 支持 ORM 对象直接转换
class StudentListResponse(BaseModel):
total: int
items: list[StudentResponse]