from pydantic import BaseModel, Field, model_validator class StudentAge(BaseModel): age_star: int | None = Field(None, gt=0) age_end: int | None = Field(None, gt=0) age_value: int | None = Field(None, gt=0) @model_validator(mode="after") def check_age(self): if self.age_value is not None: if self.age_star is not None or self.age_end is not None: raise ValueError('age_value和age_star/age_end区间不能同时存在') else: if self.age_star is None or self.age_end is None: raise ValueError('区间需填写完整') if self.age_star is not None and self.age_end is not None: if self.age_star > self.age_end: raise ValueError('输入起始值不能大于终止值') return self class ClassCount(BaseModel): class_id: int = Field(..., gt=0) gender: str | None = Field(None, description="可填男/女") class ScoreCount(BaseModel): score: int = Field(..., ge=0, le=100) num: int | None = Field(None, gt=0) class ScoreAvg(BaseModel): exam_order: int = Field(...) class Employment(BaseModel): top: int = Field(...) class EmploymentOff(BaseModel): class_id: int = Field(...)