git.ithinksw.org
/
~kgodey
/
maayanwich.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9d0f2e4
)
Made the user field on the sandwich auto fill in and removed it from the displayed...
author
Kriti Godey
<kriti.godey@gmail.com>
Fri, 5 Mar 2010 04:53:13 +0000
(23:53 -0500)
committer
Kriti Godey
<kriti.godey@gmail.com>
Fri, 5 Mar 2010 04:53:13 +0000
(23:53 -0500)
forms.py
patch
|
blob
|
history
views.py
patch
|
blob
|
history
diff --git
a/forms.py
b/forms.py
index
380f6a4
..
a2c5fc8
100644
(file)
--- a/
forms.py
+++ b/
forms.py
@@
-8,7
+8,7
@@
class SandwichForm(ModelForm):
class Meta:
model = Sandwich
class Meta:
model = Sandwich
- exclude = ('slug',)
+ exclude = ('slug',
'user'
)
class IngredientForm(ModelForm):
class IngredientForm(ModelForm):
diff --git
a/views.py
b/views.py
index
2a175af
..
9e1ee35
100644
(file)
--- a/
views.py
+++ b/
views.py
@@
-18,12
+18,13
@@
def add_sandwich(request):
if request.method == 'POST': # If the form has been submitted...
form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
if request.method == 'POST': # If the form has been submitted...
form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
- newsandwich = form.save()
+ newsandwich = form.save(commit=False)
+ newsandwich.user = request.user
newsandwich.save()
thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
return HttpResponse(thankshtml) # Redirect after POST
else:
newsandwich.save()
thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
return HttpResponse(thankshtml) # Redirect after POST
else:
- form = SandwichForm() # An unbound form
+ form = SandwichForm(
initial={'user': request.user}
) # An unbound form
return render_to_response('sandwich.html', {'sform': form, 'sandwiches': sandwiches, 'user': request.user,})
else:
thankshtml = "<p class=\"formthanks\">You are not logged in.</p>"
return render_to_response('sandwich.html', {'sform': form, 'sandwiches': sandwiches, 'user': request.user,})
else:
thankshtml = "<p class=\"formthanks\">You are not logged in.</p>"