1 from django.http import HttpResponse
2 from forms import SandwichForm, IngredientForm
3 from django.shortcuts import render_to_response
4 from django.core.files.uploadedfile import SimpleUploadedFile
5 from django.template.defaultfilters import slugify
6 from models import Sandwich, Ingredient
11 def add_sandwich(request):
12 if request.method == 'POST': # If the form has been submitted...
13 form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
14 if form.is_valid(): # All validation rules pass
15 newsandwich = form.save()
17 thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
18 return HttpResponse(thankshtml) # Redirect after POST
20 form = SandwichForm() # An unbound form
22 return render_to_response('sandwich.html', {'sform': form,})
25 def add_ingredient(request):
26 if request.method == 'POST': # If the form has been submitted...
27 form = IngredientForm(request.POST) # A form bound to the POST data
28 if form.is_valid(): # All validation rules pass
29 newsandwich = form.save()
31 thankshtml = "<p class=\"formthanks\">Thanks! Your ingredient has been saved!</p>"
32 return HttpResponse(thankshtml) # Redirect after POST
34 form = IngredientForm() # An unbound form
36 return render_to_response('ingredient.html', {'iform': form,})