26 lines
918 B
Python
26 lines
918 B
Python
from sqlalchemy import Column, String, Integer, ForeignKey, Text, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.models.base import BaseModel
|
|
from app.models.song import song_playlist
|
|
|
|
|
|
class Playlist(BaseModel):
|
|
"""Playlist model representing a collection of songs created by a user."""
|
|
|
|
__tablename__ = "playlists"
|
|
|
|
name = Column(String, nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
is_public = Column(Boolean, default=True, nullable=False)
|
|
cover_image_path = Column(String, nullable=True) # Path to playlist cover image
|
|
|
|
# Foreign keys
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="playlists")
|
|
songs = relationship("Song", secondary=song_playlist, back_populates="playlists")
|
|
|
|
def __repr__(self):
|
|
return f"<Playlist {self.name}>" |