from sqlalchemy import Column, Integer, String, Text, Float, ForeignKey, Enum from sqlalchemy.orm import relationship import enum from app.db.base_class import Base class QuestionType(str, enum.Enum): MULTIPLE_CHOICE = "multiple_choice" TRUE_FALSE = "true_false" SHORT_ANSWER = "short_answer" ESSAY = "essay" class Question(Base): id = Column(Integer, primary_key=True, index=True) exam_id = Column(Integer, ForeignKey("exam.id"), nullable=False) text = Column(Text, nullable=False) question_type = Column(Enum(QuestionType), nullable=False, default=QuestionType.MULTIPLE_CHOICE) points = Column(Float, default=1.0) image_url = Column(String(255), nullable=True) # Optional image for the question solution = Column(Text, nullable=True) # Explanation of the answer # Relationships exam = relationship("Exam", back_populates="questions") options = relationship("QuestionOption", back_populates="question", cascade="all, delete-orphan") def __repr__(self): return f""