From: Chris Fulljames Date: Sat, 7 Jun 2025 16:38:24 +0000 (-0400) Subject: Fix bug with playlist indexes X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=240b7d82d40b7f7b05e811a0d0f8654b84ac08d7;p=littlesongplace.git Fix bug with playlist indexes --- diff --git a/src/littlesongplace/playlists.py b/src/littlesongplace/playlists.py index d6d79d9..bbbb7da 100644 --- a/src/littlesongplace/playlists.py +++ b/src/littlesongplace/playlists.py @@ -98,11 +98,14 @@ def append_to_playlist(): if not song_data: abort(404) - # Set index to count of songs in list + # Set index to one more than the current max existing_songs = db.query( "select * from playlist_songs where playlistid = ?", args=[playlistid]) - new_position = len(existing_songs) + if existing_songs: + new_position = max(s["position"] for s in existing_songs) + 1 + else: + new_position = 1 # Add to playlist db.query(