fixed ingredient dropping on parser fail
This commit is contained in:
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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'])
|
||||
|
||||
|
Reference in New Issue
Block a user