-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_db.py
More file actions
22 lines (16 loc) · 814 Bytes
/
init_db.py
File metadata and controls
22 lines (16 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from recipes import db
from recipes.models import Recipe, Ingredient, RecipeIngredient
from recipes.utils.db_io import parse_ingredients
import os
if os.path.exists('recipes/site.db'):
os.remove('recipes/site.db')
db.create_all()
sample_recipe = Recipe()
sample_recipe.title = 'Kartoffeln mit Kräuterquark'
sample_recipe.instructions = '1. Kartoffeln in Wasser kochen. 2. Quark mit Schnittlauch und Petersilie, Pfeffer und Salz verrühren. Ggf. Wasser zugeben. Dann Leinöl einrühren.'
for x in parse_ingredients('\n'.join(['1 kg Kartoffeln', '1 kg Quark', 'Schnittlauch', 'Petersilie', 'Salz', 'Pfeffer', 'Leinöl'])):
a = RecipeIngredient(quantity=x[1], unit=x[2])
a.ingredient = Ingredient(name=x[0])
sample_recipe.ingredients.append(a)
db.session.add(sample_recipe)
db.session.commit()