1 from django.http import HttpResponse
2 from forms import SandwichForm, IngredientForm, ArtistForm
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, Artist, 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,})