resource.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. from sqlalchemy import (Column, Integer, String, BOOLEAN, DateTime,
  5. SmallInteger, UniqueConstraint)
  6. from db.base import Base
  7. class WorkCategory(Base):
  8. """作业资源分类
  9. """
  10. __tablename__ = "work_category"
  11. id = Column(Integer, primary_key=True, autoincrement=True)
  12. name = Column(String(20), nullable=False, comment="分类名称")
  13. pid = Column(Integer, nullable=True, comment="上级分类ID")
  14. pname = Column(String(50), nullable=True, comment="上级分类名称")
  15. period = Column(String(20), nullable=False, comment="学段")
  16. subject = Column(String(20), nullable=False, comment="学科")
  17. class WorkResource(Base):
  18. """作业资源
  19. """
  20. __tablename__ = "work_resource"
  21. id = Column(Integer, primary_key=True, autoincrement=True)
  22. category_id = Column(Integer, nullable=False, comment="资源分类id")
  23. name = Column(String(255), nullable=False, comment="资源名称")
  24. area = Column(String(20), nullable=False, comment="地区")
  25. year = Column(String(20), nullable=False, comment="年份")
  26. visit = Column(Integer, nullable=True, comment="浏览量")
  27. collect = Column(Integer, nullable=True, comment="收藏量")
  28. download = Column(Integer, nullable=True, comment="下载量")
  29. rtype = Column(String(16), default="", comment="资源类型")
  30. hot = Column(BOOLEAN(), default=False, comment="是否热点资源")
  31. attach_url = Column(String(1000), nullable=True, comment="资源附件")
  32. creator_id = Column(Integer, comment="创建人ID")
  33. creator_name = Column(String(32), comment="创建人名称")
  34. created_at = Column(DateTime, default=datetime.datetime.now)
  35. editor_id = Column(Integer, comment="最后编辑人ID")
  36. editor_name = Column(String(32), comment="最后编辑人名称")
  37. updated_at = Column(DateTime,
  38. default=datetime.datetime.now,
  39. onupdate=datetime.datetime.now)
  40. class ExamCategory(Base):
  41. """考试资源分类
  42. """
  43. __tablename__ = "exam_category"
  44. id = Column(Integer, primary_key=True, autoincrement=True)
  45. name = Column(String(20), nullable=False, comment="用户名")
  46. pid = Column(Integer, nullable=True, comment="用户名")
  47. pname = Column(String(50), nullable=True, comment="上级名称")
  48. period = Column(String(20), nullable=False, comment="学段")
  49. subject = Column(String(20), nullable=False, comment="学科")
  50. class ExamResource(Base):
  51. """考试资源
  52. """
  53. __tablename__ = "exam_resource"
  54. id = Column(Integer, primary_key=True, autoincrement=True)
  55. category_id = Column(Integer, nullable=False, comment="资源分类id")
  56. name = Column(String(255), nullable=False, comment="资源名称")
  57. area = Column(String(20), nullable=False, comment="地区")
  58. year = Column(String(20), nullable=False, comment="年份")
  59. visit = Column(Integer, nullable=True, comment="浏览量")
  60. collect = Column(Integer, nullable=True, comment="收藏量")
  61. download = Column(Integer, nullable=True, comment="下载量")
  62. attach_url = Column(String(1000), nullable=True, comment="资源附件")
  63. school_id = Column(Integer, nullable=False, comment="学校ID")
  64. school_name = Column(String(64), nullable=False, comment="学校名称")
  65. hot = Column(BOOLEAN(), default=False)
  66. creator_id = Column(Integer, comment="创建人ID")
  67. creator_name = Column(String(32), comment="创建人名称")
  68. created_at = Column(DateTime, default=datetime.datetime.now)
  69. editor_id = Column(Integer, comment="最后编辑人ID")
  70. editor_name = Column(String(32), comment="最后编辑人名称")
  71. updated_at = Column(DateTime,
  72. default=datetime.datetime.now,
  73. onupdate=datetime.datetime.now)
  74. # 资源收藏表
  75. class ResourceCollectInfo(Base):
  76. id = Column(Integer, primary_key=True, autoincrement=True)
  77. ctype = Column(String(4), nullable=False, comment="资源分类")
  78. rid = Column(Integer, nullable=False, comment="资源ID")
  79. uid = Column(Integer, nullable=False, comment="用户ID")
  80. utype = Column(SmallInteger, nullable=False, comment="用户类型,1:教师,2:学生")
  81. created_at = Column(DateTime, default=datetime.datetime.now)
  82. __tablename__ = "resource_collect_info"
  83. __table_args__ = (UniqueConstraint("uid",
  84. "utype",
  85. "rid",
  86. "ctype",
  87. name="uix_collect_uid_utype_rid_ctype"),)