category.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional, Any
  4. from pydantic import Field
  5. from pydantic.main import BaseModel
  6. from schemas.base import ListMixin, DetailMixin
  7. class SearchItem(BaseModel):
  8. id: Optional[int] = None
  9. name: str = Field(..., description="名称")
  10. class PeriodList(ListMixin):
  11. data: List[SearchItem] = []
  12. class SubjectList(ListMixin):
  13. data: List[SearchItem] = []
  14. class WorkTypeList(ListMixin):
  15. data: List[SearchItem] = []
  16. class Category(BaseModel):
  17. id: Optional[int] = None
  18. name: Optional[str] = None
  19. pid: Optional[int] = None
  20. pname: Optional[str] = None
  21. period: Optional[str] = None
  22. subject: Optional[str] = None
  23. children: Optional[Any] = None
  24. class Config:
  25. orm_mode = True
  26. class CategoryTree(Category):
  27. children: List[Category]
  28. class CategoryList(ListMixin):
  29. data: List[CategoryTree] = []
  30. class CategoryDetail(DetailMixin):
  31. data: Optional[Category] = None
  32. class UpdateCategory(BaseModel):
  33. ctype: str = Field(..., description="分类类型")
  34. name: Optional[str] = Field(None, description="分类名称")
  35. pid: Optional[int] = Field(None, description="上级分类ID")
  36. pname: Optional[str] = Field(None, description="上级分类名称")
  37. period: Optional[str] = Field(None, description="学段名称")
  38. subject: Optional[str] = Field(None, description="学科")
  39. class NewCategory(BaseModel):
  40. ctype: str = Field(..., description="分类类型")
  41. name: str = Field(..., description="分类名称")
  42. pid: int = Field(0, description="上级分类ID")
  43. pname: str = Field(None, description="上级分类名称,前端忽略,后端处理")
  44. period: str = Field(..., description="学段名称")
  45. subject: str = Field(..., description="学科")