Custom form for adding ingredients works!
[~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 from django.core.files.uploadedfile import SimpleUploadedFile
5 from django.template.defaultfilters import slugify
6 from models import Sandwich, Artist, Ingredient
7 import datetime
8
9
10
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()
16                         newsandwich.save()
17                         thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
18                         return HttpResponse(thankshtml) # Redirect after POST
19         else:
20                 form = SandwichForm() # An unbound form
21                 
22         return render_to_response('sandwich.html', {'sform': form,})
23         
24         
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()
30                         newsandwich.save()
31                         thankshtml = "<p class=\"formthanks\">Thanks! Your ingredient has been saved!</p>"
32                         return HttpResponse(thankshtml) # Redirect after POST
33         else:
34                 form = IngredientForm() # An unbound form
35
36         return render_to_response('ingredient.html', {'iform': form,})
37