diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index d99ce957d..fddb06066 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -76,7 +76,7 @@ def find_recipe_json(ld_json, url): if ingredient: ingredients.append({'amount': amount, 'unit': {'text': unit, 'id': random.randrange(10000, 99999)}, 'ingredient': {'text': ingredient, 'id': random.randrange(10000, 99999)}, "note": note, 'original': x}) except: - pass + ingredients.append({'amount': 0, 'unit': {'text': "", 'id': random.randrange(10000, 99999)}, 'ingredient': {'text': x, 'id': random.randrange(10000, 99999)}, "note": "", 'original': x}) ld_json['recipeIngredient'] = ingredients else: diff --git a/cookbook/models.py b/cookbook/models.py index f12364ab1..64c4e3d37 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -146,7 +146,7 @@ class Unit(models.Model): class Food(models.Model): - name = models.CharField(unique=True, max_length=128) + name = models.CharField(unique=True, max_length=128, validators=[MinLengthValidator(1)]) recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL) def __str__(self): diff --git a/cookbook/views/data.py b/cookbook/views/data.py index 8996b80e2..01b788661 100644 --- a/cookbook/views/data.py +++ b/cookbook/views/data.py @@ -124,7 +124,9 @@ def import_url(request): for ing in data['recipeIngredient']: ingredient = Ingredient() - ingredient.food, f_created = Food.objects.get_or_create(name=ing['ingredient']['text']) + if ing['ingredient']['text'] != '': + ingredient.food, f_created = Food.objects.get_or_create(name=ing['ingredient']['text']) + if ing['unit'] and ing['unit']['text'] != '': ingredient.unit, u_created = Unit.objects.get_or_create(name=ing['unit']['text'])