thanks for your answer
now all comments displays in my template
one other thing i want to do in this template is having a form i by witch a user can leave a comment
actualy here is my views.py
class GoodsListView(DetailView):
model = Goods
template_name = 'goods_list.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['detail'] = Goods.objects.filter(id=self.kwargs['pk']).values()
context['comment'] = Comments.objects.filter(goods=self.kwargs['pk']).\
values('goods', 'customer', 'vote_text').order_by('customer')
context['customer'] = CustomUser.objects.filter(id__in=
Comments.objects.filter(goods=self.kwargs['pk']).values('customer'))\
.values('id', 'first_name', 'last_name').order_by('id')
context['goods_main_band'] = MainBranch.objects.filter(mb_code__in=
Goods.objects.filter(id=self.kwargs['pk']).values('goods_main_band_id')).values('main_desc')
context['goods_sub_band1'] = SubBranch1.objects.filter(sb1_code__in=
Goods.objects.filter(id=self.kwargs['pk']).values('goods_sub_band1_id')).values('sb1_desc')
context['goods_specification'] = GoodsSpecification.objects.filter(goods_sub_band2__in=
Goods.objects.filter(id=self.kwargs['pk']).values('goods_sub_band2_id')).values('spec_desc')
context['goods_properties'] = GoodsProperties.objects.filter(goods_sub_band2__in=
Goods.objects.filter(id=self.kwargs['pk']).values('goods_sub_band2_id'))\
.values('goods_intro', 'goods_criticize')
return context
class GoodsDetailView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
view = CommentGet.as_view()
return view(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
view = CommentPost.as_view()
return view(request, *args, **kwargs)
class CommentGet(DetailView):
model = Comments
template_name = "goods_detail.html"
def get_object(self, queryset=None):
return Goods.objects.get(pk=self.kwargs.get('pk'))
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["form"] = CommentForm()
return context
class CommentPost(SingleObjectMixin, FormView):
model = Comments
form_class = CommentForm
template_name = 'goods_detail.html'
def post(self, request, *args, **kwargs):
self.object = self.get_object()
return super().post(request, *args, **kwargs)
def form_valid(self, form):
comment = form.save(commit=False)
self.object = self.get_object()
comment.goods = self.object
comment.save()
return super().form_valid(form)
def get_success_url(self):
goods = self.get_object()
return reverse("goods_detail", kwargs={"pk": goods.pk})
and urls.py
urlpatterns = [
path('about/', AboutPageView.as_view(), name='about'),
path('?/', GoodsSearchView.as_view(), name='gsview'),
path('?/<int:pk>/', GoodsListView.as_view(), name='goods_list'),
path('?/<int:pk>/comment', GoodsDetailView.as_view(), name='goods_detail'),
]
i can reach new comment page by adding /comment at thr end of url but i want to display comment form in product page