first commit
This commit is contained in:
54
backend/models.py
Normal file
54
backend/models.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from backend.database import Base
|
||||
|
||||
|
||||
class Question(Base):
|
||||
__tablename__ = "questions"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
chapter: Mapped[str] = mapped_column(Text, default="")
|
||||
primary_knowledge: Mapped[str] = mapped_column(Text, default="")
|
||||
secondary_knowledge: Mapped[str] = mapped_column(Text, default="")
|
||||
question_type: Mapped[str] = mapped_column(Text, default="")
|
||||
difficulty: Mapped[str] = mapped_column(Text, default="")
|
||||
stem: Mapped[str] = mapped_column(Text)
|
||||
option_a: Mapped[str] = mapped_column(Text, default="")
|
||||
option_b: Mapped[str] = mapped_column(Text, default="")
|
||||
option_c: Mapped[str] = mapped_column(Text, default="")
|
||||
option_d: Mapped[str] = mapped_column(Text, default="")
|
||||
answer: Mapped[str] = mapped_column(Text, default="")
|
||||
explanation: Mapped[str] = mapped_column(Text, default="")
|
||||
notes: Mapped[str] = mapped_column(Text, default="")
|
||||
source_file: Mapped[str] = mapped_column(Text, default="")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
|
||||
class Category(Base):
|
||||
__tablename__ = "categories"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
name: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
parent_id: Mapped[int | None] = mapped_column(ForeignKey("categories.id"), nullable=True)
|
||||
level: Mapped[int] = mapped_column(Integer, default=1)
|
||||
|
||||
children: Mapped[list["Category"]] = relationship(
|
||||
"Category", backref="parent", remote_side=[id], lazy="joined"
|
||||
)
|
||||
|
||||
|
||||
class ImportHistory(Base):
|
||||
__tablename__ = "import_history"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
filename: Mapped[str] = mapped_column(Text, default="")
|
||||
method: Mapped[str] = mapped_column(Text, default="manual")
|
||||
question_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
status: Mapped[str] = mapped_column(Text, default="success")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
Reference in New Issue
Block a user