school.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.base import Base
  6. class School(Base):
  7. id = Column(Integer, primary_key=True, autoincrement=True)
  8. name = Column(String(100), nullable=False, comment="学校名称")
  9. area_code = Column(String(100), nullable=False, comment="所在区域code,使用,分隔")
  10. area_name = Column(String(100),
  11. nullable=False,
  12. comment="所在区域,如:四川省,成都市,双流区")
  13. category = Column(Integer, default=0, comment="学校类型,0:小学,1:初中,2:高中,3:大学")
  14. contact_name = Column(String(20), nullable=False, comment="联系人")
  15. contact_phone = Column(String(20), default="", comment="联系人电话")
  16. is_active = Column(BOOLEAN(), default=True)
  17. creator_id = Column(Integer, comment="创建人ID")
  18. creator_name = Column(String(32), comment="创建人名称")
  19. created_at = Column(DateTime, default=datetime.datetime.now)
  20. editor_id = Column(Integer, comment="最后编辑人ID")
  21. editor_name = Column(String(32), comment="最后编辑人名称")
  22. updated_at = Column(DateTime,
  23. default=datetime.datetime.now,
  24. onupdate=datetime.datetime.now)
  25. __table_args__ = (UniqueConstraint("name", name="uix_school_name"),)
  26. class SchoolGrade(Base):
  27. id = Column(Integer, primary_key=True, autoincrement=True)
  28. name = Column(String(20), nullable=False, comment="年级名称")
  29. school_id = Column(Integer, nullable=False, comment="所属学校")
  30. teacher_amount = Column(Integer, default=0, comment="教师人数")
  31. student_amount = Column(Integer, default=0, comment="学生人数")
  32. __table_args__ = (UniqueConstraint("name",
  33. "school_id",
  34. name="uix_name_school_id"),)
  35. class SchoolClass(Base):
  36. id = Column(Integer, primary_key=True, autoincrement=True)
  37. name = Column(String(20), nullable=False, comment="班级名称")
  38. school_id = Column(Integer, nullable=False, comment="所属学校")
  39. school_name = Column(String(100), nullable=False, comment="学校名称")
  40. grade_id = Column(Integer, nullable=False, comment="所属年级")
  41. grade_name = Column(String(20), nullable=False, comment="年级名称")
  42. teacher_amount = Column(Integer, default=0, comment="教师人数")
  43. student_amount = Column(Integer, default=0, comment="学生人数")
  44. creator_id = Column(Integer, comment="创建人ID")
  45. creator_name = Column(String(32), comment="创建人名称")
  46. created_at = Column(DateTime, default=datetime.datetime.now)
  47. editor_id = Column(Integer, comment="最后编辑人ID")
  48. editor_name = Column(String(32), comment="最后编辑人名称")
  49. updated_at = Column(DateTime,
  50. default=datetime.datetime.now,
  51. onupdate=datetime.datetime.now)
  52. __table_args__ = (UniqueConstraint("school_id",
  53. "grade_id",
  54. "name",
  55. name="uix_school_id_grade_id_name"),)
  56. # 学制列表
  57. class SchoolSystem(Base):
  58. id = Column(Integer, primary_key=True, autoincrement=True)
  59. name = Column(String(20), nullable=False, comment="学制名称")
  60. grades = Column(String(100), nullable=False, comment="年级列表,逗号分隔")