def choose_ingredients(request): if request.method == 'POST': form = IngredientForm(request.POST) if form.is_valid(): picked = form.cleaned_data.get('picked') ingredients = '' for ing in picked: ingredients += ing + '+' else: form = IngredientForm return render(request, 'choose_ingredients.html', {'form' : form}) return redirect('/recipes/list/%s' % ingredients)
def get(self, request, pk=None): x = get_object_or_404(Recipe, id=pk, owner=self.request.user) form = CreateForm(instance=x) # x = Recipe.objects.get(id=pk) ingredients = Ingredient.objects.filter(recipe=x).order_by('-created_at') ingredient_form = IngredientForm() context = {'recipe':x, 'ingredients':ingredients, 'ingredient_form':ingredient_form, 'form': form} return render(request, self.template_name, context)
def recipe_list(request): response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=apples%2Cflour%2Csugar&number=5", ======= def choose_ingredients(request): if request.method == 'POST': form = IngredientForm(request.POST) if form.is_valid(): picked = form.cleaned_data.get('picked') ingredients = '' for ing in picked: ingredients += ing + '+' else: form = IngredientForm return render(request, 'choose_ingredients.html', {'form' : form}) return redirect('/recipes/list/%s' % ingredients) def recipe_list(request, ingredients): temp_ing = ingredients.split('+') search_string = '' for ingredient in temp_ing: search_string += ingredient + "%2C" search_string = search_string[:-6] print(search_string) response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=" + search_string + "&number=10", >>>>>>> be8d88bdb6587541493f2c93f91ebdbc8d0618eb headers={ "X-Mashape-Key": "QN5CLcAiQXmshOrib4vl7QifQAPjp1MjXoijsnsKdgztp93FnI", "Accept": "application/json" } ) context = { <<<<<<< HEAD 'response': response } return render(request, 'recipes_list.html', context) ======= 'recipes': response, 'ingredients': ingredients, }