I am new to Flask and i'm trying to make something that requires some skills I am not able to find an answer to when searching SO.
So, the concept is... I have a list of songs that is generated dynamically. Basically we don't know how many there will be. The songs are stored in a list within a list, like this:
[[id,artist_name,track_name],[id,artist_name,track_name],[id,artist_name,track_name] etc]
I would like to create a form with a SelectField for every list in the list so that the user can give scores to every song in the list.
The route passing on the list item looks like this:
@app.route('/submitlist', methods=['GET', 'POST'])
def submitlist():
form = forms.Playlist()
if request.method == 'POST':
if form.validate():
song_data = [[id,artist_name,track_name],[id,artist_name,track_name]...]
session['thesongs'] = song_data
return redirect(url_for('songs'))
return render_template('songs.html', form=form)
The route receiving the list looks like this:
@app.route('/songs', methods=['GET', 'POST'])
def songs():
form = forms.SongsRated()
if request.method == 'POST':
data = form.rating.data
session['results'] = data
return redirect(url_for('results'))
return render_template('songs.html', thesongs=session['thesongs'], form=form)
What I am unable to figure out is what the form SongsRated should look like as is should return a dynamic number of SelectFields. I should also be able to collect the return value and identify which SelectField value belongs to which item in the list (thesongs).
And finally I would like to do some verification as I would only like the user be able to score 10 songs (no matter how many) and the scores should all be unique (1-10).
I am sorry if this wasn't explained very well.
Thanks in advance.