def edit_post(request, year, month, day, slug): """Edit an existing blog post.""" post = get_model_for_date_and_slug(Post, year, month, day, slug) form = PostForm(instance=post) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save() if "continue_editing" in request.POST: return http.HttpResponseRedirect(post.get_edit_url()) return http.HttpResponseRedirect(post.get_absolute_url()) return render_to_response("montgomery/edit_post.html", {"form": form}, context_instance=RequestContext(request))
def create_post(request): """Create new post.""" form = PostForm() if request.method == "POST": form = PostForm(data=request.POST) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() form.save_m2m() # necessary to save tags return http.HttpResponseRedirect(post.get_absolute_url()) return render_to_response("montgomery/create_post.html", {"form": form}, context_instance=RequestContext(request))