school.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. from sqlalchemy import Column, Integer, String, BOOLEAN, DateTime, UniqueConstraint
  5. from db import BaseORMModel
  6. class School(BaseORMModel):
  7. __tablename__ = "schools"
  8. id = Column(Integer, primary_key=True, autoincrement=True)
  9. name = Column(String(100), nullable=False, comment="学校名称")
  10. area_code = Column(String(100), nullable=False, comment="所在区域code,使用,分隔")
  11. area_name = Column(String(100), nullable=False, comment="所在区域,如:四川省,成都市,双流区")
  12. category = Column(Integer, default=0, comment="学校类型,0:小学,1:初中,2:高中,3:大学")
  13. contact_name = Column(String(20), nullable=False, comment="联系人")
  14. contact_phone = Column(String(20), default="", comment="联系人电话")
  15. is_active = Column(BOOLEAN(), default=True, comment="是否激活")
  16. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  17. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  18. created_at = Column(DateTime, default=datetime.datetime.now)
  19. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  20. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  21. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  22. __table_args__ = (UniqueConstraint("name", name="uix_school_name"),)
  23. class SchoolGrade(BaseORMModel):
  24. __tablename__ = "school_grades"
  25. id = Column(Integer, primary_key=True, autoincrement=True)
  26. name = Column(String(20), nullable=False, comment="年级名称")
  27. order = Column(Integer, nullable=False, comment="序号")
  28. school_id = Column(Integer, nullable=False, comment="所属学校")
  29. teacher_amount = Column(Integer, default=0, comment="教师人数")
  30. student_amount = Column(Integer, default=0, comment="学生人数")
  31. __table_args__ = (UniqueConstraint("name", "school_id", name="uix_name_school_id"),)
  32. class SchoolClass(BaseORMModel):
  33. __tablename__ = "school_classes"
  34. id = Column(Integer, primary_key=True, autoincrement=True)
  35. name = Column(String(20), nullable=False, comment="班级名称")
  36. school_id = Column(Integer, nullable=False, comment="所属学校")
  37. school_name = Column(String(100), nullable=False, comment="学校名称")
  38. grade_id = Column(Integer, nullable=False, comment="所属年级")
  39. grade_name = Column(String(20), nullable=False, comment="年级名称")
  40. teacher_amount = Column(Integer, default=0, comment="教师人数")
  41. student_amount = Column(Integer, default=0, comment="学生人数")
  42. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  43. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  44. created_at = Column(DateTime, default=datetime.datetime.now)
  45. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  46. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  47. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  48. __table_args__ = (UniqueConstraint("school_id",
  49. "grade_id",
  50. "name",
  51. name="uix_school_id_grade_id_name"),)
  52. # 学制列表
  53. class SchoolSystem(BaseORMModel):
  54. __tablename__ = "school_systems"
  55. id = Column(Integer, primary_key=True, autoincrement=True)
  56. name = Column(String(20), nullable=False, comment="学制名称")
  57. grades = Column(String(100), nullable=False, comment="年级列表,逗号分隔")
  58. # class Subject(Base):
  59. #
  60. # __tablename__ = "subjects"
  61. #
  62. # id = Column(Integer, primary_key=True, autoincrement=True)
  63. # name = Column(String(20), nullable=False, comment="学科名称")
  64. #
  65. # __table_args__ = (UniqueConstraint("name", name="uix_subjects_name"),)