I am making a simple bbs in Django.
At the moment, I am trying to make it possible to delete a post in front-end.
This is my code in views.py
@login_required
def delete_post(request, id):
post_to_delete = get_object_or_404(Post, pk=id)
if post_to_delete.owner_user != request.user:
return HttpResponseForbidden()
if request.method == 'POST':
form = DeletePostForm(request.POST, instance=post_to_delete)
if form.is_valid():
post_to_delete.delete()
return HttpResponseRedirect('/')
else:
form = DeletePostForm(instance=post_to_delete)
return render(request,'delete_post.html', {'form':form})
I believe I am using the .delete() function correctly and when I click my delete button, I am taken to the delete_post.html but when i go back to check the list of posts in admin, the post is still there..