123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from typing import List, Optional, Union, Any, Dict
- from pydantic import BaseModel, Field
- from schemas.base import Datetime2Str, ListMixin, DetailMixin
- class StudentItem(BaseModel):
- id: int
- sno: Optional[str] = None
- name: Optional[str] = None
- sex: Optional[int] = None
- age: Optional[int] = None
- phone: Optional[str] = None
- school_id: Optional[int] = None
- school_name: Optional[str] = None
- grade_id: Optional[int] = None
- grade_name: Optional[str] = None
- class_id: Optional[int] = None
- class_name: Optional[str] = None
- created_at: Optional[Datetime2Str] = None
- class Config:
- orm_mode = True
- class StudentList(ListMixin):
- data: List[StudentItem] = []
- class StudentDetail(DetailMixin):
- data: Union[Dict[str, Any], StudentItem] = None
- class NewStudent(BaseModel):
- sno: str = Field(..., max_length=20, description="学号")
- name: str = Field(..., max_lenght=20, description="学生姓名")
- sex: int = Field(0, ge=0, le=1, description="性别, 0:女,1 :男")
- age: int = Field(0, description="年龄")
- phone: str = Field(..., max_length=11, description="手机号")
- school_id: int = Field(..., alias="sid", description="学校ID")
- grade_id: int = Field(..., alias="gid", description="年级ID")
- class_id: int = Field(..., alias="cid", description="班级ID")
- class Config:
- anystr_strip_whitespace = True
- class StudentInDB(NewStudent):
- school_name: str = Field(..., description="学校名称")
- grade_name: str = Field(..., description="年级名称")
- class_name: str = Field(..., description="班级名称")
- username: str = Field(..., description="用户名")
- password: str = Field(..., max_length=64, description="密码")
- creator_id: int = Field(..., description="创建人ID")
- creator_name: str = Field(..., description="创建人姓名")
- editor_id: int = Field(..., description="最后编辑人ID")
- editor_name: str = Field(..., description="最后编辑人姓名")
- class UpdateStudent(BaseModel):
- # sno: Optional[str] = Field(None, max_length=20, description="学号")
- name: Optional[str] = Field(None, max_lenght=20, description="学生姓名")
- sex: Optional[int] = Field(None, ge=0, le=1, description="性别, 0:女,1:男")
- age: Optional[int] = Field(None, description="年龄")
- phone: Optional[str] = Field(None, max_length=11, description="手机号")
- school_id: Optional[int] = Field(None, alias="sid", description="学校ID")
- school_name: Optional[str] = Field(None,
- max_length=100,
- description="学校名称,前端忽略,后端处理")
- grade_id: Optional[int] = Field(None, alias="gid", description="年级ID")
- grade_name: Optional[str] = Field(None,
- max_length=20,
- description="年级名称,前端忽略,后端处理")
- class_id: Optional[int] = Field(None, alias="cid", description="班级ID")
- class_name: Optional[str] = Field(None,
- max_length=20,
- description="班级名称,前端忽略,后端处理")
- editor_id: int = Field(None, description="最后编辑人ID,前端忽略,后端处理")
- editor_name: str = Field(None, description="最后编辑人姓名,前端忽略,后端处理")
- class Config:
- anystr_strip_whitespace = True
|