From: Kriti Godey Date: Fri, 19 Mar 2010 20:26:56 +0000 (-0400) Subject: Editing a sandwich works, except for the ingredients. X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/commitdiff_plain/221dc8d141126bb1329fc9b010918cd6851ccd67 Editing a sandwich works, except for the ingredients. --- diff --git a/templates/editsandwich.html b/templates/editsandwich.html index f70bc85..912b6bb 100644 --- a/templates/editsandwich.html +++ b/templates/editsandwich.html @@ -29,7 +29,7 @@ $(function() {% block content %}

Edit sandwich

-
+ {{ sform.as_p }} {% if s.picture %} diff --git a/views.py b/views.py index e47a17f..dc62977 100644 --- a/views.py +++ b/views.py @@ -54,8 +54,6 @@ def add_sandwich(request): def edit_sandwich(request, slug): sedit = Sandwich.objects.get(slug=slug) - if sedit.picture: - savedpicture = sedit.picture.url if request.user.is_authenticated(): if not sedit.user == request.user: return HttpResponseRedirect(reverse('all_sandwiches')) @@ -63,24 +61,24 @@ def edit_sandwich(request, slug): if request.method == 'POST': sform = SandwichForm(request.POST, request.FILES, instance=sedit) if sform.is_valid(): # All validation rules pass - newsandwich = sform.save() + sedit.adjective = request.POST['adjective'] + sedit.date_made = request.POST['date_made'] + sedit.notes = request.POST['notes'] + if request.POST['picture']: + sedit.picture = request.POST['picture'] x = request.POST['ing'] x = x.strip() y = x.split(',') for n in y: if n.isdigit(): - newsandwich.ingredients.add(Ingredient.objects.get(id=n)) + sedit.ingredients.add(Ingredient.objects.get(id=n)) else: n = n.lstrip('new:') newingredient = Ingredient(name=n, slug=SlugifyUniquely(n, Ingredient)) newingredient.save() - newsandwich.ingredients.add(newingredient) - if not newsandwich.picture: - if savedpicture: - newsandwich.picture = savedpicture - newsandwich.slug = slug - newsandwich.save() - return HttpResponseRedirect(newsandwich.get_absolute_url()) + sedit.ingredients.add(newingredient) + sedit.save() + return HttpResponseRedirect(sedit.get_absolute_url()) else: sform = SandwichForm(instance=sedit) return render_to_response('editsandwich.html', {'sform': sform, 's':sedit,}, context_instance=RequestContext(request))