
- 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
21 lines
824 B
Python
21 lines
824 B
Python
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Float
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class Result(Base):
|
|
__tablename__ = "results"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(String(100), index=True, nullable=False) # External user ID
|
|
quiz_id = Column(Integer, ForeignKey("quizzes.id"))
|
|
score = Column(Float, nullable=False) # Percentage score
|
|
total_questions = Column(Integer, nullable=False)
|
|
correct_answers = Column(Integer, nullable=False)
|
|
time_taken = Column(Float, nullable=True) # Time taken in seconds
|
|
completed_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Relationships
|
|
quiz = relationship("Quiz", back_populates="results") |