From 240b7d82d40b7f7b05e811a0d0f8654b84ac08d7 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sat, 7 Jun 2025 12:38:24 -0400 Subject: [PATCH] Fix bug with playlist indexes --- src/littlesongplace/playlists.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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( -- 2.39.5