post = models.ForeignKey(
Article,
related_name='post',
on_delete=models.CASCADE,
editable=False # !!!
)
def article(request, slug):
article = get_object_or_404(Article, slug__iexact=slug)
# Комментарии
if request.method == 'POST':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment_form.instance.author = request.user
comment_form.instance.post = article
comment_form.save()
return redirect('/')
else:
comment_form = CommentForm()
comments = Comment.objects.order_by('-pk')
context = {
'article': article,
'comments': comments,
'comment_form': comment_form,
}
return render(request, 'home/one_news.html', context)