12345678910111213141516171819202122232425262728293031 |
- from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
- from sqlalchemy.orm import relationship
- from .base_model import BaseModel, CreateModel, UpdateModel, DeleteModel
- class QuestionModel(BaseModel, CreateModel, UpdateModel, DeleteModel):
- """
- 题目模型
- 对应数据库表: questions
- """
- __tablename__ = 'questions'
- subject = Column(String(50), nullable=False, comment='学科')
- type = Column(String(50), nullable=False, comment='题型')
- difficulty = Column(Integer, nullable=False, comment='难度等级')
- content = Column(Text, nullable=False, comment='题目内容')
- answer = Column(Text, comment='答案')
- explanation = Column(Text, comment='解析')
- version = Column(String(20), comment='题目版本')
- tags = Column(String(255), comment='题目标签')
- # 与选项的一对多关系
- options = relationship('QuestionOptionModel', back_populates='question')
- # 与知识点的多对多关系
- knowledge_points = relationship('KnowledgePointModel',
- secondary='question_knowledge_points',
- back_populates='questions')
- def __repr__(self):
- return f"<Question(id={self.id}, content={self.content[:20]}...)>"
|