Skip to content

Instantly share code, notes, and snippets.

@IbrahimAyed1
Created September 20, 2018 14:28
Show Gist options
  • Select an option

  • Save IbrahimAyed1/670b6f54d19f04d59b8fe8ec186a5612 to your computer and use it in GitHub Desktop.

Select an option

Save IbrahimAyed1/670b6f54d19f04d59b8fe8ec186a5612 to your computer and use it in GitHub Desktop.
Menu Item App
from flask import Flask, render_template
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from db_test import Base, Restaurant, MenuItem
app = Flask(__name__)
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
@app.route('/restaurants/<int:restaurant_id>/')
def restaurantMenu(restaurant_id):
restaurants = session.query(Restaurant).filter_by(id=restaurant_id).one()
items = session.query(MenuItem).filter_by(restaurant_id=restaurants.id)
return render_template('menu.html', restaurant=restaurants, items=items)
# Task 1: Create route for newMenuItem function here
@app.route('/restaurants/<int:restaurant_id>/new/')
def newMenuItem(restaurant_id):
return "page to create a new menu item. Task 1 complete!"
# Task 2: Create route for editMenuItem function here
@app.route('/restaurants/<int:restaurant_id>/<int:menu_id>/edit/')
def editMenuItem(restaurant_id, menu_id):
return "page to edit a menu item. Task 2 complete!"
# Task 3: Create a route for deleteMenuItem function here
@app.route('/restaurants/<int:restaurant_id>/<int:menu_id>/delte/')
def deleteMenuItem(restaurant_id, menu_id):
return "page to delete a menu item. Task 3 complete!"
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment