]> littlesong.place Git - littlesongplace.git/commitdiff
Fix bug with playlist indexes
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 7 Jun 2025 16:38:24 +0000 (12:38 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 7 Jun 2025 16:38:24 +0000 (12:38 -0400)
src/littlesongplace/playlists.py

index d6d79d9ae7ff66722bbe594de62070bf2949ceeb..bbbb7da5dabcf693199fe737988bb64700588d3a 100644 (file)
@@ -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(