finished backend upgrades to allow multiple courses
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import List, Optional
|
||||
|
||||
import pytz
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy import Boolean, Column, DateTime, String, TypeDecorator, ForeignKey
|
||||
from sqlalchemy import Boolean, Column, DateTime, String, TypeDecorator, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
db : SQLAlchemy = SQLAlchemy()
|
||||
|
||||
@@ -61,10 +61,15 @@ class Password(db.Model):
|
||||
class Deck(db.Model):
|
||||
__tablename__ = "deck"
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('course_id', 'deck', name='_course_deck_uc'),
|
||||
)
|
||||
|
||||
id : Mapped[int] = mapped_column(primary_key=True)
|
||||
name : Mapped[str] = mapped_column(String(60), unique=True, nullable=False)
|
||||
deck : Mapped[str] = mapped_column(String(60), unique=True, nullable=False)
|
||||
deck : Mapped[str] = mapped_column(String(60), nullable=False)
|
||||
description : Mapped[str] = mapped_column(String(60))
|
||||
index_file: Mapped[str] = mapped_column(String(40), nullable=False)
|
||||
|
||||
passwords : Mapped[List[Password]] = relationship("Password", secondary=deck_password, back_populates='decks')
|
||||
tokens : Mapped[List[Token]] = relationship("Token", secondary=deck_token, back_populates='decks')
|
||||
@@ -72,14 +77,15 @@ class Deck(db.Model):
|
||||
course: Mapped['Course'] = relationship("Course", back_populates='decks')
|
||||
|
||||
|
||||
def __init__(self, name: str, deck: str, course: Course, description: str = "") -> None:
|
||||
def __init__(self, name: str, deck: str, course: Course, description: str = "", index_file: str = "index.html") -> None:
|
||||
self.name = name
|
||||
self.deck = deck
|
||||
self.description = description
|
||||
self.course = course
|
||||
self.index_file = index_file
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Deck(name={self.name}, deck={self.deck}, course={self.course})>"
|
||||
return f"<Deck(name={self.name}, deck={self.deck}, course={self.course}, index={self.index_file})>"
|
||||
|
||||
class Token(db.Model):
|
||||
__tablename__ = "token"
|
||||
@@ -101,11 +107,13 @@ class Token(db.Model):
|
||||
class Course(db.Model):
|
||||
__tablename__ = "course"
|
||||
id : Mapped[int] = mapped_column(primary_key=True)
|
||||
folder: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
||||
name: Mapped[str] = mapped_column(String(60), unique=True, nullable=False)
|
||||
decks: Mapped[List['Deck']] = relationship(back_populates='course')
|
||||
|
||||
def __init__(self, name: str) -> None:
|
||||
def __init__(self, name: str, folder: str) -> None:
|
||||
self.name = name
|
||||
self.folder = folder
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Course(id={self.id}, name={self.name})>"
|
||||
|
||||
Reference in New Issue
Block a user