def post(self, request, pk) : f = get_object_or_404(Auto, id=pk) comment_form = CommentForm(request.POST) comment = Comment(text=request.POST['comment'], owner=request.user, auto=f) comment.save() return redirect(reverse_lazy('auto_detail', args=[pk]))
def get(self, request, pk): auto = Auto.objects.get(id=pk) comments = Comment.objects.filter(auto=auto).order_by('-updated_at') comment_form = CommentForm() context = { 'auto': auto, 'comments': comments, 'comment_form': comment_form } return render(request, self.template_name, context)