DocDoeAI / app /models /previous_question.py
asnannp's picture
Deploy backend cd4237ff: support routes + rate limit + exam_date nullable + upload 413 fix
7c6ffa6
Raw
History Blame Contribute Delete
2.72 kB
from __future__ import annotations
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, JSON, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.database import Base
from app.utils.ids import prefixed_id
if TYPE_CHECKING:
from app.models.previous_paper import PreviousPaper
class PreviousQuestion(Base):
__tablename__ = "previous_questions"
id: Mapped[str] = mapped_column(
String(40),
primary_key=True,
default=lambda: prefixed_id("pq"),
)
previous_paper_id: Mapped[str] = mapped_column(
String(40),
ForeignKey("previous_papers.id", ondelete="CASCADE"),
index=True,
nullable=False,
)
question_number: Mapped[str | None] = mapped_column(String(40), nullable=True)
question_text: Mapped[str] = mapped_column(Text, nullable=False)
marks: Mapped[int | None] = mapped_column(Integer, nullable=True)
subject: Mapped[str | None] = mapped_column(String(120), nullable=True)
syllabus: Mapped[str | None] = mapped_column(String(120), nullable=True)
year: Mapped[int | None] = mapped_column(Integer, nullable=True)
chapter: Mapped[str | None] = mapped_column(String(180), nullable=True)
topic: Mapped[str | None] = mapped_column(String(180), nullable=True)
question_type: Mapped[str] = mapped_column(
String(40),
default="unknown",
nullable=False,
)
difficulty: Mapped[str] = mapped_column(
String(40),
default="unknown",
nullable=False,
)
keywords_json: Mapped[list[str]] = mapped_column(JSON, default=list, nullable=False)
# ── T2: Enhanced PYQ extraction fields ──────────────────────────────────
answer_type: Mapped[str | None] = mapped_column(String(40), nullable=True)
formula_needed: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
diagram_needed: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
extracted_answer_if_available: Mapped[str | None] = mapped_column(Text, nullable=True)
confidence: Mapped[float] = mapped_column(Float, default=0.0, nullable=False)
source_origin: Mapped[str] = mapped_column(
String(30),
default="user_uploaded",
nullable=False,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
nullable=False,
)
previous_paper: Mapped["PreviousPaper"] = relationship(
"PreviousPaper",
back_populates="questions",
)