60 lines
1.3 KiB
Python
60 lines
1.3 KiB
Python
from typing import Optional, List, TYPE_CHECKING
|
|
from enum import Enum
|
|
from pydantic import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.schemas.question_option import QuestionOption
|
|
|
|
|
|
# Question type enum
|
|
class QuestionType(str, Enum):
|
|
MULTIPLE_CHOICE = "multiple_choice"
|
|
TRUE_FALSE = "true_false"
|
|
SHORT_ANSWER = "short_answer"
|
|
ESSAY = "essay"
|
|
|
|
|
|
# Shared properties
|
|
class QuestionBase(BaseModel):
|
|
exam_id: int
|
|
text: str
|
|
question_type: QuestionType = QuestionType.MULTIPLE_CHOICE
|
|
points: float = 1.0
|
|
image_url: Optional[str] = None
|
|
solution: Optional[str] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class QuestionCreate(QuestionBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class QuestionUpdate(BaseModel):
|
|
text: Optional[str] = None
|
|
question_type: Optional[QuestionType] = None
|
|
points: Optional[float] = None
|
|
image_url: Optional[str] = None
|
|
solution: Optional[str] = None
|
|
|
|
|
|
class QuestionInDBBase(QuestionBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Question(QuestionInDBBase):
|
|
pass
|
|
|
|
|
|
# Question with options
|
|
class QuestionWithOptions(Question):
|
|
options: List['QuestionOption'] = []
|
|
|
|
|
|
# Update forward references
|
|
from app.schemas.question_option import QuestionOption # noqa: E402
|
|
QuestionWithOptions.model_rebuild() |