Refactor code structure for improved readability and maintainability
This commit is contained in:
37
app/models/playlist_sound.py
Normal file
37
app/models/playlist_sound.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlmodel import Field, Relationship, UniqueConstraint
|
||||
|
||||
from app.models.base import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.models.playlist import Playlist
|
||||
from app.models.sound import Sound
|
||||
|
||||
|
||||
class PlaylistSound(BaseModel, table=True):
|
||||
"""Database model for a sound in a playlist."""
|
||||
|
||||
__tablename__ = "playlist_sound" # pyright: ignore[reportAssignmentType]
|
||||
|
||||
playlist_id: int = Field(foreign_key="playlist.id", nullable=False)
|
||||
sound_id: int = Field(foreign_key="sound.id", nullable=False)
|
||||
position: int = Field(default=0, ge=0, nullable=False)
|
||||
|
||||
# constraints
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"playlist_id",
|
||||
"sound_id",
|
||||
name="uq_playlist_sound_playlist_sound",
|
||||
),
|
||||
UniqueConstraint(
|
||||
"playlist_id",
|
||||
"position",
|
||||
name="uq_playlist_sound_playlist_position",
|
||||
),
|
||||
)
|
||||
|
||||
# relationships
|
||||
playlist: "Playlist" = Relationship(back_populates="playlist_sounds")
|
||||
sound: "Sound" = Relationship(back_populates="playlist_sounds")
|
||||
Reference in New Issue
Block a user