Select Field in flask forms / flask_wtf is not changing unless I rerun the flask app

Viewed 402

So I have a flask form that contains a select field with some options... what I'm trying to achieve is that when a user chooses an option and submits the form, that option should disappear the next time someone tries to access the form. And it's working only if I stop the app.py and run it again. I want the form to refresh its content every time someone tries to access it without the need to rerun the app.

my flask form:

class ReserveForm(FlaskForm):
    rooms = Room.query.filter_by(is_reserved=0, request=None)
    roomList = []
    for room in rooms:
        roomList.append(room)
    room = SelectField('Room', choices=roomList)

my code for the user view:

@app.route('/reserve', methods=['GET', 'POST'])
@login_required
def reserve():

    form = ReserveForm()
    if form.validate_on_submit():
        student_id = current_user.id
        room_num = int(form.room.data)

        newRequest = ReserveRequest(student_id=student_id, room_num=room_num)
        db.session.add(newRequest)
        db.session.commit()

        return '<h1>done<h1>'
    return render_template('reserve.html', form=form)
0 Answers
Related