Answer the question
In order to leave comments, you need to log in
How to specify the associated model?
views.py
class Comment(CreateView):
model = Comment
form_class = CommentForm
template_name = 'article_detail.html'
success_url = '/'
def form_valid(self, form):
instance = form.save(commit=False)
instance.comment_article = Article.objects.get(id=1)
instance.save()
return super(Comment, self).form_valid(form)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question