fixed empty units/foods (again)

This commit is contained in:
vabene1111
2021-03-19 00:19:29 +01:00
parent 7fbff9f3b5
commit f04a51c1ad
9 changed files with 79 additions and 19 deletions

View File

@ -3,7 +3,7 @@ import re
from io import BytesIO
from zipfile import ZipFile
from cookbook.helper.ingredient_parser import parse
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
from cookbook.integration.integration import Integration
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
@ -34,8 +34,8 @@ class NextcloudCookbook(Integration):
for ingredient in recipe_json['recipeIngredient']:
amount, unit, ingredient, note = parse(ingredient)
f, created = Food.objects.get_or_create(name=ingredient, space=self.request.space)
u, created = Unit.objects.get_or_create(name=unit, space=self.request.space)
f = get_food(ingredient, self.request.space)
u = get_unit(unit, self.request.space)
step.ingredients.add(Ingredient.objects.create(
food=f, unit=u, amount=amount, note=note
))