mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 20:30:38 +04:00
Update database architecture. Add genres and actors
This commit is contained in:
25
database/models/audiobook_genres.py
Normal file
25
database/models/audiobook_genres.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class AudiobookGenre(Base):
|
||||
__tablename__ = "audiobook_genres"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
genre = Column(String, nullable=False, unique=True)
|
||||
|
||||
audiobooks = relationship("Audiobook", secondary="audiobook_to_genre",
|
||||
lazy="selectin")
|
||||
|
||||
|
||||
class AudiobookToGenre(Base):
|
||||
__tablename__ = "audiobook_to_genre"
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint("audiobook_id", "genre_id"),
|
||||
)
|
||||
|
||||
audiobook_id = Column(Integer, ForeignKey("audiobooks.id"), nullable=False)
|
||||
genre_id = Column(Integer, ForeignKey(
|
||||
"audiobook_genres.id"), nullable=False)
|
||||
Reference in New Issue
Block a user