student.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional, Union, Any, Dict
  4. from pydantic import BaseModel, Field
  5. from schemas.base import Datetime2Str, ListMixin, DetailMixin
  6. class StudentItem(BaseModel):
  7. id: int
  8. sno: Optional[str] = None
  9. name: Optional[str] = None
  10. sex: Optional[int] = None
  11. age: Optional[int] = None
  12. phone: Optional[str] = None
  13. school_id: Optional[int] = None
  14. school_name: Optional[str] = None
  15. grade_id: Optional[int] = None
  16. grade_name: Optional[str] = None
  17. class_id: Optional[int] = None
  18. class_name: Optional[str] = None
  19. created_at: Optional[Datetime2Str] = None
  20. class Config:
  21. orm_mode = True
  22. class StudentList(ListMixin):
  23. data: List[StudentItem] = []
  24. class StudentDetail(DetailMixin):
  25. data: Union[Dict[str, Any], StudentItem] = None
  26. class NewStudent(BaseModel):
  27. sno: str = Field(..., max_length=20, description="学号")
  28. name: str = Field(..., max_lenght=20, description="学生姓名")
  29. sex: int = Field(0, ge=0, le=1, description="性别, 0:女,1 :男")
  30. age: int = Field(0, description="年龄")
  31. phone: str = Field(..., max_length=11, description="手机号")
  32. school_id: int = Field(..., alias="sid", description="学校ID")
  33. grade_id: int = Field(..., alias="gid", description="年级ID")
  34. class_id: int = Field(..., alias="cid", description="班级ID")
  35. class Config:
  36. anystr_strip_whitespace = True
  37. class StudentInDB(NewStudent):
  38. school_name: str = Field(..., description="学校名称")
  39. grade_name: str = Field(..., description="年级名称")
  40. class_name: str = Field(..., description="班级名称")
  41. username: str = Field(..., description="用户名")
  42. password: str = Field(..., max_length=64, description="密码")
  43. creator_id: int = Field(..., description="创建人ID")
  44. creator_name: str = Field(..., description="创建人姓名")
  45. editor_id: int = Field(..., description="最后编辑人ID")
  46. editor_name: str = Field(..., description="最后编辑人姓名")
  47. class UpdateStudent(BaseModel):
  48. # sno: Optional[str] = Field(None, max_length=20, description="学号")
  49. name: Optional[str] = Field(None, max_lenght=20, description="学生姓名")
  50. sex: Optional[int] = Field(None, ge=0, le=1, description="性别, 0:女,1:男")
  51. age: Optional[int] = Field(None, description="年龄")
  52. phone: Optional[str] = Field(None, max_length=11, description="手机号")
  53. school_id: Optional[int] = Field(None, alias="sid", description="学校ID")
  54. school_name: Optional[str] = Field(None,
  55. max_length=100,
  56. description="学校名称,前端忽略,后端处理")
  57. grade_id: Optional[int] = Field(None, alias="gid", description="年级ID")
  58. grade_name: Optional[str] = Field(None,
  59. max_length=20,
  60. description="年级名称,前端忽略,后端处理")
  61. class_id: Optional[int] = Field(None, alias="cid", description="班级ID")
  62. class_name: Optional[str] = Field(None,
  63. max_length=20,
  64. description="班级名称,前端忽略,后端处理")
  65. editor_id: int = Field(None, description="最后编辑人ID,前端忽略,后端处理")
  66. editor_name: str = Field(None, description="最后编辑人姓名,前端忽略,后端处理")
  67. class Config:
  68. anystr_strip_whitespace = True