def post(self, request, pk): form = ReviewForm(request.POST) post = News.objects.get(id=pk) if form.is_valid(): form = form.save(commit=False) form.post = post form.user = request.user form.save() return redirect(post.get_absolute_url())
def review_new(request, mentor_pk): user = Profile.objects.get(user=request.user) if user.is_mentor: messages.info(request, "잘못된 접근입니다") return redirect('blog:mentor_detail', mentor_pk) else: if request.method == 'POST': form = ReviewForm(request.POST) if form.is_valid(): review = form.save(commit=False) review.mentee = Profile.objects.get(user__username=str(request.user)) review.mentor = get_object_or_404(Profile, pk=mentor_pk) review.save() messages.info(request, '리뷰를 등록했습니다.') return redirect('blog:mentor_detail', mentor_pk) else: form = ReviewForm() return render(request, 'blog/review_form.html', {'form': form})
def review_edit(request, mentor_pk, pk): review = Review.objects.get(pk=pk) if review.mentee.user != request.user: messages.warning(request, "작성자가 아닙니다") return redirect("blog:mentor_detail", mentor_pk) else: if request.method == 'POST': form = ReviewForm(request.POST, instance=review) if form.is_valid(): review = form.save(commit=False) review.mentee = Profile.objects.get(user__username=str(request.user)) review.mentor = get_object_or_404(Profile, pk=mentor_pk) review.save() messages.info(request, '리뷰를 수정했습니다') return redirect('blog:mentor_detail', mentor_pk) else: form = ReviewForm(instance=review) return render(request, 'blog/review_form.html', {'form': form, })
def add_review_to_post(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = ReviewForm(request.POST) if form.is_valid(): review = form.save(commit=False) review.post = post review.save() return redirect('post_detail', pk=post.pk) else: form = ReviewForm() return render(request, 'blog/review_form.html', {'form': form})