def delete_song(cls, song_id): song = Song().get(song_id, links=True) if song is None: raise NotFoundException() # remove the song from storage first song.remove() # deleting a song also deletes all the associated versions for v in song.versions: version = Version().get(v, links=True) version.remove() # then remove the singer and re-index any related objects SongIndex.delete_by_id(song.id)