def hostPoll(): header = "Enter your desired poll!" form = PollForm() if form.validate_on_submit(): # We need to create the session and the poll, then link them # together. sesh = Session(session_id=form.sessionID.data) poll = Poll(question=form.questionText.data) session = Session.query.filter_by( session_id=form.sessionID.data).first() # If the session doesn't exist if not (session is None): flash('Session in use!') return redirect('/host_poll') poll.a = form.a.data poll.b = form.b.data poll.c = form.c.data poll.d = form.d.data poll.a_num = 0 poll.b_num = 0 poll.c_num = 0 poll.d_num = 0 # Link them poll.session = sesh sesh.poll = poll db.session.add(sesh) db.session.commit() db.session.add(poll) db.session.commit() flash("Generating poll!") return redirect('/pollData/' + sesh.session_id) return render_template('create_poll.html', title='Host a Poll', header=header, form=form)