<p><label for="id_ing">Ingredients:</label> <input id="id_ing" type="text" name="ing"/></p>
<input type="submit" value="Submit" />
</form>
+ {% ifequal s.user request.user %}<p class="sandnotes"><a href="{% url del_sandwich slug=s.slug %}">Delete sandwich</a></p>{% endifequal %}
</span>
{% endblock %}
\ No newline at end of file
url(r'^sandwich/addingredient/$', views.add_ingredient, name='add_ingredient'),
url(r'^sandwich/all/$', views.all_sandwich, name='all_sandwiches'),
url(r'^sandwich/(?P<slug>[-\w]+)/edit/', views.edit_sandwich, name='edit_sandwich'),
+ url(r'^sandwich/(?P<slug>[-\w]+)/delete/', views.del_sandwich, name='del_sandwich'),
url(r'^sandwich/(?P<slug>[-\w]+)/$', views.specific_sandwich, name='sandwich_by_slug'),
url(r'^sandwich/(?P<year>[-\w]+)/(?P<month>[-\w]+)/$', views.sandwich_month, name='sandwich_by_month'),
url(r'^login/$', views.login_view, name='login'),
return render_to_response('editsandwich.html', {'sform': sform, 's':sedit, 'prepop': ingred, }, context_instance=RequestContext(request))
else:
return HttpResponseRedirect(reverse('login2'))
+
+def del_sandwich(request, slug):
+ if request.user.is_authenticated():
+ if Sandwich.objects.get(slug=slug):
+ del_sandwich = Sandwich.objects.get(slug=slug)
+ if request.user == del_sandwich.user:
+ del_sandwich.delete()
+ return HttpResponseRedirect(reverse('all_sandwiches'))
+ else:
+ return HttpResponseRedirect(reverse('all_sandwiches'))
+ else:
+ return HttpResponseRedirect(reverse('login2'))
def add_ingredient(request):
if request.user.is_authenticated():