65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from typing import Optional, List, TYPE_CHECKING
|
|
from datetime import datetime
|
|
from pydantic import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.schemas.question import Question
|
|
from app.schemas.user import User
|
|
|
|
# Shared properties
|
|
class ExamBase(BaseModel):
|
|
title: str
|
|
description: Optional[str] = None
|
|
course_id: int
|
|
duration_minutes: int = 60
|
|
passing_score: float = 50.0
|
|
is_active: bool = True
|
|
is_randomized: bool = False
|
|
start_time: Optional[datetime] = None
|
|
end_time: Optional[datetime] = None
|
|
created_by: Optional[int] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class ExamCreate(ExamBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class ExamUpdate(ExamBase):
|
|
title: Optional[str] = None
|
|
course_id: Optional[int] = None
|
|
duration_minutes: Optional[int] = None
|
|
passing_score: Optional[float] = None
|
|
is_active: Optional[bool] = None
|
|
is_randomized: Optional[bool] = None
|
|
|
|
|
|
class ExamInDBBase(ExamBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Exam(ExamInDBBase):
|
|
pass
|
|
|
|
|
|
# Exam with questions
|
|
class ExamWithQuestions(Exam):
|
|
questions: List['Question'] = []
|
|
|
|
# Exam with creator info
|
|
class ExamWithCreator(Exam):
|
|
creator: Optional['User'] = None
|
|
|
|
|
|
# Update forward references
|
|
from app.schemas.question import Question # noqa: E402
|
|
from app.schemas.user import User # noqa: E402
|
|
ExamWithQuestions.model_rebuild()
|
|
ExamWithCreator.model_rebuild() |