I want users to use checkboxes to determine toppings that are on a new pizza.
I have a collection called ingredients for veg, meat, cheese and sauce. And I have a collection called pizzas.
I want to pull all possible ingredents from each category, display them on screen, allow the user to check the ones that are on a pizza then submit it. The submission would go to the pizza collection.
At the moment veg, meat, cheese and sauce have their own dictionaries pulled into a python file called app.py:
meats = mongo.db.ingredients.find_one({'meats' : {'$exists': True}})
vegs = mongo.db.ingredients.find_one({'vegs' : {'$exists': True}})
sauces = mongo.db.ingredients.find_one({'sauces' : {'$exists': True}})
cheeses = mongo.db.ingredients.find_one({'cheeses' : {'$exists': True}})
They are then passed into the addpizza.html file:
@app.route('/add_pizza')
def add_pizza():
return render_template("addpizza.html",
meats = meats,
vegs = vegs,
sauces = sauces,
cheeses = cheeses)
Pizza collection example:
{"_id":{"$oid":"5d506eed1c9d4400000a4254"},"pizza_name":"vegetairian supreme","pizza_code":"vs","sauce_type":"pizza","cheese_type":"mozzarella","toppings":["onions","mushrooms","peppers","sweetcorn","tomatoes"],"allergens":"","is_veg":true}
Ingredient collection example:
{"_id":{"$oid":"5d5353ee1c9d440000cb278e"},"meats":["bacon","beef","roast chicken","tandoori chicken","ham","meatballs","pepperoni","chorizo","sausage"]}
addpizza.html, at the moment I am only trying to display meat toppings to the user:
<h3>Add Pizza</h3>
<div class="row">
<form action="" method="POST" class="col s12">
<div class="row">
<div class="input-field col s12">
</div>
<div class="row">
<button class="btn waves-effect waves-light" type="submit" name="action">Add Pizza
<i class="material-icons right">playlist_add</i>
</button>
</div>
</form>
</div>
This displays checkboxes and each individual meat. However regardless of which checkbox you try to check, it will check the first one then send you to the top of the page.
Aucun commentaire:
Enregistrer un commentaire