This commit is contained in:
smilerz
2021-04-20 08:09:42 -05:00
parent 66bb5b4328
commit 2b5dceee7c

View File

@@ -131,23 +131,25 @@ def import_url(request):
recipe.steps.add(step) recipe.steps.add(step)
for kw in data['keywords']: for kw in data['keywords']:
if k := Keyword.objects.filter(name=kw['text'], space=request.space).first(): # if k := Keyword.objects.filter(name=kw['text'], space=request.space).first():
recipe.keywords.add(k) # recipe.keywords.add(k)
elif data['all_keywords']: # elif data['all_keywords']:
k = Keyword.objects.create(name=kw['text'], space=request.space) # k = Keyword.objects.create(name=kw['text'], space=request.space)
recipe.keywords.add(k) # recipe.keywords.add(k)
k = Keyword.objects.get_or_create(name=kw['text'].strip(), space=request.space)
recipe.keywords.add(k)
for ing in data['recipeIngredient']: for ing in data['recipeIngredient']:
ingredient = Ingredient() ingredient = Ingredient()
if ing['ingredient']['text'] != '': if ing['ingredient']['text'] != '':
ingredient.food, f_created = Food.objects.get_or_create( ingredient.food, f_created = Food.objects.get_or_create(
name=ing['ingredient']['text'], space=request.space name=ing['ingredient']['text'].strip(), space=request.space
) )
if ing['unit'] and ing['unit']['text'] != '': if ing['unit'] and ing['unit']['text'] != '':
ingredient.unit, u_created = Unit.objects.get_or_create( ingredient.unit, u_created = Unit.objects.get_or_create(
name=ing['unit']['text'], space=request.space name=ing['unit']['text'].strip(), space=request.space
) )
# TODO properly handle no_amount recipes # TODO properly handle no_amount recipes