22 lines
1.0 KiB
Python
22 lines
1.0 KiB
Python
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"<StudentAnswer {self.id}: Result {self.exam_result_id}, Question {self.question_id}>" |