M
Size: a a a
M
С
M
N
С
Б
MB
Б
MB
Б
J
J
def post_detail(request, pk):
template_name = 'books/post-detail.html'
book = get_object_or_404(Book, pk=pk)
comments = book.comments.filter(active=True)
new_comment = None
# Comment posted
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
# Create Comment object but don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
new_comment.comment = book
new_comment.username = request.user
# Save the comment to the database
new_comment.save()
else:
comment_form = CommentForm()
context = {'book': book,
'comments': comments,
'new_comment': new_comment,
'comment_form': comment_form}
return render(request, template_name, context)
MB
AS
AK
PA
AK
AG
MS
AK