Update app
This commit is contained in:
@@ -93,6 +93,21 @@ class Display(db.Model):
|
||||
assigned_playlist_id = db.Column(db.Integer, db.ForeignKey("playlist.id"), nullable=True)
|
||||
assigned_playlist = db.relationship("Playlist")
|
||||
|
||||
# Multi-playlist support (active playlists per display).
|
||||
# If a display has any rows in display_playlist, those are used by the player.
|
||||
# If not, we fall back to assigned_playlist_id for backwards compatibility.
|
||||
display_playlists = db.relationship(
|
||||
"DisplayPlaylist",
|
||||
back_populates="display",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
playlists = db.relationship(
|
||||
"Playlist",
|
||||
secondary="display_playlist",
|
||||
viewonly=True,
|
||||
order_by="Playlist.name.asc()",
|
||||
)
|
||||
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
company = db.relationship("Company", back_populates="displays")
|
||||
@@ -117,6 +132,32 @@ class DisplaySession(db.Model):
|
||||
__table_args__ = (db.UniqueConstraint("display_id", "sid", name="uq_display_session_display_sid"),)
|
||||
|
||||
|
||||
class DisplayPlaylist(db.Model):
|
||||
"""Association table: which playlists are active on a display."""
|
||||
|
||||
# NOTE: Some existing databases include an `id` INTEGER PRIMARY KEY column and a
|
||||
# NOT NULL `position` column on display_playlist. We keep the mapper primary key as
|
||||
# (display_id, playlist_id) for portability, while allowing an optional `id` column
|
||||
# to exist in the underlying table.
|
||||
id = db.Column(db.Integer, nullable=True)
|
||||
|
||||
# Composite mapper PK ensures uniqueness per display.
|
||||
display_id = db.Column(db.Integer, db.ForeignKey("display.id"), primary_key=True)
|
||||
playlist_id = db.Column(db.Integer, db.ForeignKey("playlist.id"), primary_key=True)
|
||||
|
||||
# Ordering of playlists within a display.
|
||||
position = db.Column(db.Integer, default=1, nullable=False)
|
||||
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
display = db.relationship("Display", back_populates="display_playlists")
|
||||
playlist = db.relationship("Playlist")
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint("display_id", "playlist_id", name="uq_display_playlist_display_playlist"),
|
||||
)
|
||||
|
||||
|
||||
class AppSettings(db.Model):
|
||||
"""Singleton-ish app-wide settings.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user