コード例 #1
0
ファイル: views.py プロジェクト: katiesandford/RecipeWebsite
 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)
コード例 #2
0
ファイル: views.py プロジェクト: robesson/AppsPy
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))