initial
This commit is contained in:
13
database/__init__.py
Normal file
13
database/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from .models import Base, Cartoon, Season, Episode
|
||||
|
||||
__all__ = ['session', 'Cartoon', 'Season', 'Episode']
|
||||
|
||||
engine = create_engine('sqlite:///cartoons.db')
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
37
database/models.py
Normal file
37
database/models.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Cartoon(Base):
|
||||
__tablename__ = 'cartoons'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String, nullable=False)
|
||||
|
||||
seasons = relationship("Season", backref="cartoon", order_by="Season.season_number")
|
||||
|
||||
|
||||
class Season(Base):
|
||||
__tablename__ = 'seasons'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
season_number = Column(Integer, nullable=False)
|
||||
cartoon_id = Column(Integer, ForeignKey('cartoons.id'), nullable=False)
|
||||
|
||||
episodes = relationship("Episode", backref="season", order_by="Episode.episode_number")
|
||||
|
||||
|
||||
class Episode(Base):
|
||||
__tablename__ = 'episodes'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
episode_number = Column(Integer, nullable=False)
|
||||
season_id = Column(Integer, ForeignKey('seasons.id'), nullable=False)
|
||||
file = Column(String, nullable=False)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user