mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 20:30:38 +04:00
26 lines
789 B
Python
26 lines
789 B
Python
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", viewonly=True)
|
|
|
|
|
|
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)
|