def edit_plan(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == 'POST': form = PostForm(request.POST, request.FILES, instance=post) if form.is_valid(): form.save() messages.info(request, "수정이 되었습니다.") return redirect('magazine:index') else: form = PostForm(instance=post) return render(request, "plan/form.html", { 'form': form, })
def create_plan(request): if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() #form.save_m2m() messages.success(request, "새 계획이 추가되었습니다.") return redirect('plan:index') else: form = PostForm() return render(request, "plan/form.html", { 'form': form, })