Architecture:
- Questions are primary objects in a bank, tagged with question categories
- QuestionCategory is a separate taxonomy from QuizCategory (different concepts)
- Extraction → questions added to bank, optionally tagged to a question category
- Quizzes can be created from: individual question selection, question category, or PDF extraction
Backend:
- QuestionCategory model + question_categories table
- question_category_id column on questions table (nullable, SET NULL on delete)
- GET/POST/PATCH/DELETE /api/question-categories/
- POST /api/question-categories/{id}/create-quiz — create quiz from all questions in a category
- PATCH /api/questions/{id}/category — assign single question to category
- PATCH /api/questions/bulk-category — assign multiple questions at once
- GET /api/questions/bank?category_id=&uncategorized= — filter by category
- QuizCreate schema now accepts question_category_id for extraction
- quiz_service.create_quiz_from_section accepts question_category_id param
Frontend:
- DocumentDetailPage: Add to Bank Category dropdown in Quiz Settings (optional)
Labels extracted questions with the selected category on creation
- QuestionBankPage: full rewrite
- Category chips for filtering (All / Uncategorized / named categories)
- Create category button inline
- Checkbox multi-select with bulk category assignment
- Create Quiz modal: choose from selected questions OR all from a category
- Each question shows its category badge and quiz source
- Study modal with instant answer feedback
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
from pgvector.sqlalchemy import Vector
|
|
from sqlalchemy import Column, Integer, String, Text, JSON, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.config import settings
|
|
from app.database import Base
|
|
from app.models.question_category import QuestionCategory # noqa — ensures mapper resolves
|
|
|
|
|
|
class Question(Base):
|
|
__tablename__ = "questions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
quiz_id = Column(Integer, ForeignKey("quizzes.id", ondelete="CASCADE"), nullable=False)
|
|
question_category_id = Column(Integer, ForeignKey("question_categories.id", ondelete="SET NULL"), nullable=True)
|
|
question_text = Column(Text, nullable=False)
|
|
question_type = Column(String, nullable=False) # mcq, true_false, fill_blank
|
|
options = Column(JSON, nullable=True) # list of strings for mcq
|
|
correct_answer = Column(String, nullable=False)
|
|
explanation = Column(Text, nullable=True)
|
|
page_reference = Column(Integer, nullable=True)
|
|
image_path = Column(String, nullable=True)
|
|
embedding = Column(Vector(1024), nullable=True) # semantic search vector
|
|
|
|
quiz = relationship("Quiz", back_populates="questions")
|
|
question_category = relationship("QuestionCategory", back_populates="questions",
|
|
foreign_keys=[question_category_id])
|