from sqlalchemy import Column, Integer, Text, Boolean, ForeignKey, Float from sqlalchemy.orm import relationship from app.db.base_class import Base class StudentAnswer(Base): id = Column(Integer, primary_key=True, index=True) exam_result_id = Column(Integer, ForeignKey("exam_result.id"), nullable=False) question_id = Column(Integer, ForeignKey("question.id"), nullable=False) selected_option_id = Column(Integer, ForeignKey("question_option.id"), nullable=True) # For multiple choice/true-false text_answer = Column(Text, nullable=True) # For short answer/essay is_correct = Column(Boolean, nullable=True) # Whether the answer is correct points_earned = Column(Float, default=0.0) # Points earned for this answer # Relationships exam_result = relationship("ExamResult", back_populates="answers") question = relationship("Question") selected_option = relationship("QuestionOption") def __repr__(self): return f""