Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     self.object = None
     form_class = self.get_form_class()
     form = self.get_form(form_class)
     form_is_valid = form.is_valid()
     ingredient_form = IngredientFormSet(request.POST, request.FILES)
     ingredient_form_is_valid = ingredient_form.is_valid()
     recipe_step_form = RecipeStepFormSet(request.POST, request.FILES)
     recipe_step_form_is_valid = recipe_step_form.is_valid()
     if form_is_valid and ingredient_form_is_valid and recipe_step_form_is_valid:
         return self.form_valid(form, ingredient_form, recipe_step_form)
     return self.form_invalid(form, ingredient_form, recipe_step_form)
     
     
     return super(RecipeCreate, self).post(request, *args, **kwargs)
Ejemplo n.º 2
0
def index(request):
    if request.POST:

        form = UserSubmittedRecipeForm(request.POST)

        if form.is_valid():
            recipe = form.save(commit=False)
            ingredient_formset = IngredientFormSet(request.POST, instance=recipe)

            if ingredient_formset.is_valid():
                recipe.save()
                ingredient_formset.save()    

                return HttpResponseRedirect(reverse('index'))

    else:
        form = UserSubmittedRecipeForm()
        ingredient_formset = IngredientFormSet(instance=Recipe())
        
    return render_to_response("submit.html", {
        "form": form,
        "ingredient_formset": ingredient_formset,
    }, context_instance=RequestContext(request))