def edit_menu_item(restaurant_id, menu_id): """ Edit a given menu item for a given restaurant. """ item_to_edit = session.query(MenuItem).filter_by(id=menu_id).one() form = MenuItemForm(request.form, item_to_edit) if form and request.method == 'POST': if form.validate(): form.populate_obj(item_to_edit) session.add(item_to_edit) session.commit() flash("Menu item edited.") return redirect(url_for('show_menu', restaurant_id=restaurant_id, menu_id=menu_id)) else: return render_template('editMenuItem.html', restaurant_id=restaurant_id, menu_id=menu_id, form=form, item=item_to_edit) else: return render_template('editMenuItem.html', restaurant_id=restaurant_id, menu_id=menu_id, form=form, item=item_to_edit)
def new_menu_item(restaurant_id): """ Create a new menu item for a given restaurant """ form = MenuItemForm(request.form) if form and request.method == 'POST': if form.validate(): new_item = MenuItem( name=request.form.get('name'), course=request.form.get('course'), description=request.form.get('description'), price=request.form.get('price'), restaurant_id=restaurant_id ) session.add(new_item) session.commit() flash("New menu item created!") return redirect(url_for('show_menu', restaurant_id=restaurant_id)) else: return render_template('newMenuItem.html', restaurant_id=restaurant_id, form=form) else: return render_template('newMenuItem.html', restaurant_id=restaurant_id, form=form)