30 lines
1.5 KiB
Python
30 lines
1.5 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, ForeignKey, Float
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Exam(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(200), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
course_id = Column(Integer, ForeignKey("course.id"), nullable=False)
|
|
duration_minutes = Column(Integer, default=60)
|
|
passing_score = Column(Float, default=50.0) # Percentage required to pass
|
|
is_active = Column(Boolean, default=True)
|
|
is_randomized = Column(Boolean, default=False) # Whether questions should be randomized
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
start_time = Column(DateTime, nullable=True) # When the exam becomes available
|
|
end_time = Column(DateTime, nullable=True) # When the exam becomes unavailable
|
|
created_by = Column(Integer, ForeignKey("user.id"), nullable=True)
|
|
|
|
# Relationships
|
|
course = relationship("Course", backref="exams")
|
|
questions = relationship("Question", back_populates="exam", cascade="all, delete-orphan")
|
|
exam_results = relationship("ExamResult", back_populates="exam", cascade="all, delete-orphan")
|
|
creator = relationship("User", back_populates="created_exams")
|
|
|
|
def __repr__(self):
|
|
return f"<Exam {self.title}>" |