49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
#这是学生就业管理系统的请求模型
|
||||
|
|
|
|||
|
|
from datetime import date
|
|||
|
|
|
|||
|
|
from fastapi import HTTPException
|
|||
|
|
from pydantic import BaseModel, Field, field_validator, model_validator,ConfigDict
|
|||
|
|
|
|||
|
|
|
|||
|
|
class StudentWorkCreate(BaseModel):
|
|||
|
|
sid :int = Field(...,ge=0,le=10000,description="输入0-10000之间的学生编号")
|
|||
|
|
open_time:date = Field(...,description="要写如下格式YYYY-MM-DD ")
|
|||
|
|
offer_time:date = Field(...,description="要写如下格式YYYY-MM-DD ")
|
|||
|
|
company_name: str = Field(...,max_length=50,description="公司名字")
|
|||
|
|
salary :float = Field(...,ge=0.1,le=10000.0,description="月薪")
|
|||
|
|
|
|||
|
|
@model_validator(mode="after")
|
|||
|
|
def time_available(self):
|
|||
|
|
if self.open_time>self.offer_time:
|
|||
|
|
raise HTTPException(status_code=422,detail="就业时间必须大于offer下发时间")
|
|||
|
|
return self
|
|||
|
|
class StudentWorkCreate1(BaseModel):
|
|||
|
|
sid :int = Field(...,ge=0,le=10000,description="输入0-10000之间的学生编号")
|
|||
|
|
company_name: str = Field(..., max_length=50, description="公司名字")
|
|||
|
|
salary: float = Field(..., ge=0.1, le=1000000.0, description="月薪")
|
|||
|
|
class StudentWorks(BaseModel):
|
|||
|
|
sid: int = Field(...,ge=0,le=10000,description="输入0-10000之间的你想修改的学生编号")
|
|||
|
|
# s_name:str =Field(...,max_length=50,description="学生姓名")
|
|||
|
|
# s_class : int = Field(...,ge = 1,le = 100,description="学生班级编号")
|
|||
|
|
open_time: date = Field(description="输入你修改后的时间,要写如下格式YYYY-MM-DD, ",default=date(1970,1,1))
|
|||
|
|
offer_time: date = Field( description="输入你修改后的时间,要写如下格式YYYY-MM-DD ",default=date(1970,1,1))
|
|||
|
|
company_name: str = Field( max_length=50, description="输入你修改后的公司名字",default="0")
|
|||
|
|
salary: float|int = Field( ge=0.1, le=100000.0, description="输入你修改后的月薪",default=0)
|
|||
|
|
|
|||
|
|
@model_validator(mode="after")
|
|||
|
|
def time_available(self):
|
|||
|
|
if self.open_time > self.offer_time:
|
|||
|
|
raise HTTPException(status_code=422, detail="就业时间必须大于offer下发时间")
|
|||
|
|
return self
|
|||
|
|
# 允许 Pydantic 读取 SQLAlchemy ORM 对象
|
|||
|
|
model_config = ConfigDict(from_attributes=True)
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|