Added a view for a form to add a sandwich, made a url for it and made a templates...
[~kgodey/maayanwich.git] / views.py
1 from django.http import HttpResponse
2 from forms import SandwichForm, IngredientForm, ArtistForm
3 from django.shortcuts import render_to_response
4
5
6 def add_sandwich(request):
7         if request.method == 'POST': # If the form has been submitted...
8                 form = SandwichForm(request.POST) # A form bound to the POST data
9                 if form.is_valid(): # All validation rules pass
10                         # Process the data in form.cleaned_data
11                         # ...
12                         thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
13                         return HttpResponse(thankshtml) # Redirect after POST
14         else:
15                 form = SandwichForm() # An unbound form
16                 
17         return render_to_response('sandwich.html', {'form': form,})