def players_create(team_id): form = PlayerForm(request.form) p = Player(form.name.data, form.number.data) p.team_id = team_id db.session().add(p) db.session().commit() return redirect(url_for("players_index"))
def players_create(): error = None form = PlayerForm(team_id=current_user.team_id) if form.validate_on_submit(): try: p = Player(number=form.number.data, name=form.name.data) p.team_id = current_user.team_id db.session.add(p) db.session.commit() flash("Player added") except Exception as e: error = e return redirect(url_for("players_index")) return render_template("/players/new.html", form=form, error=error)