Skip to content

Instantly share code, notes, and snippets.

@siumhossain
Created January 27, 2021 17:32
Show Gist options
  • Save siumhossain/0057676059277ce2e46278dbe02ec0f2 to your computer and use it in GitHub Desktop.
Save siumhossain/0057676059277ce2e46278dbe02ec0f2 to your computer and use it in GitHub Desktop.
a important comment view for me
def post_single(request, post):
post = get_object_or_404(Post, slug=post, status='published')
comments = post.comments.filter(status=True)
user_comment = None
if request.method == 'POST':
comment_form = NewCommentForm(request.POST)
if comment_form.is_valid():
user_comment = comment_form.save(commit=False)
user_comment.post = post
user_comment.save()
return HttpResponseRedirect('/' + post.slug)
else:
comment_form = NewCommentForm()
return render(request, 'single.html', {'post': post, 'comments': user_comment, 'comments': comments, 'comment_form': comment_form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment