question_model.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
  2. from sqlalchemy.orm import relationship
  3. from .base_model import BaseModel, CreateModel, UpdateModel, DeleteModel
  4. class QuestionModel(BaseModel, CreateModel, UpdateModel, DeleteModel):
  5. """
  6. 题目模型
  7. 对应数据库表: questions
  8. """
  9. __tablename__ = 'questions'
  10. subject = Column(String(50), nullable=False, comment='学科')
  11. type = Column(String(50), nullable=False, comment='题型')
  12. difficulty = Column(Integer, nullable=False, comment='难度等级')
  13. content = Column(Text, nullable=False, comment='题目内容')
  14. answer = Column(Text, comment='答案')
  15. explanation = Column(Text, comment='解析')
  16. version = Column(String(20), comment='题目版本')
  17. tags = Column(String(255), comment='题目标签')
  18. # 与选项的一对多关系
  19. options = relationship('QuestionOptionModel', back_populates='question')
  20. # 与知识点的多对多关系
  21. knowledge_points = relationship('KnowledgePointModel',
  22. secondary='question_knowledge_points',
  23. back_populates='questions')
  24. def __repr__(self):
  25. return f"<Question(id={self.id}, content={self.content[:20]}...)>"