
- Setup project structure with FastAPI app - Create SQLAlchemy models for categories, questions, quizzes, and results - Implement API endpoints for all CRUD operations - Set up Alembic migrations for database schema management - Add comprehensive documentation in README.md
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from sqlalchemy import Column, Integer, String, Text, ForeignKey, Table
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
|
|
# Association table for many-to-many relationship between questions and quizzes
|
|
question_quiz = Table(
|
|
"question_quiz",
|
|
Base.metadata,
|
|
Column("question_id", Integer, ForeignKey("questions.id"), primary_key=True),
|
|
Column("quiz_id", Integer, ForeignKey("quizzes.id"), primary_key=True)
|
|
)
|
|
|
|
|
|
class Question(Base):
|
|
__tablename__ = "questions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
text = Column(Text, nullable=False)
|
|
answer = Column(String(255), nullable=False)
|
|
option1 = Column(String(255), nullable=True)
|
|
option2 = Column(String(255), nullable=True)
|
|
option3 = Column(String(255), nullable=True)
|
|
difficulty = Column(String(20), nullable=True) # easy, medium, hard
|
|
reference = Column(String(100), nullable=True) # Bible reference (e.g., "John 3:16")
|
|
category_id = Column(Integer, ForeignKey("categories.id"))
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="questions")
|
|
quizzes = relationship("Quiz", secondary=question_quiz, back_populates="questions") |