def freeboard_edit(request, pk): freeboard = Freeboard.objects.get(pk=pk) if request.method == 'POST': form = FreeboardForm(request.POST, instance=freeboard) if form.is_valid(): freeboard = form.save() return redirect('blog:freeboard_detail', pk) else: form = FreeboardForm(instance=freeboard) return render(request, 'blog/freeboard_form.html', {'form': form})
def freeboard_new(request): if request.method == 'POST': form = FreeboardForm(request.POST) if form.is_valid(): freeboard = form.save(commit=False) freeboard.author = Profile.objects.get(user=request.user) freeboard.save() return redirect('blog:freeboard') else: form = FreeboardForm() return render(request, 'blog/freeboard_form.html', {'form': form})