Exemple #1
0
    def post(self, request, pk) :
        f = get_object_or_404(Ad, id=pk)
        comment_form = CommentForm(request.POST)

        comment = Comment(text=request.POST['comment'], owner=request.user, ad=f)
        comment.save()
        return redirect(reverse_lazy('ad_detail', args=[pk]))
Exemple #2
0
 def get(self, request, pk):
     x = Ad.objects.get(id=pk)
     comments = Comment.objects.filter(ad=x).order_by('-updated_at')
     # (ad=x): 'ad': field in the model; 'x': variable in the view
     comment_form = CommentForm()
     context = {'ad': x, 'comments': comments, 'comment_form': comment_form}
     return render(request, self.template_name, context)
 def get(self, request, pk):
     ad = Ad.objects.get(id=pk)
     comments = Comment.objects.filter(ad=ad).order_by('-updated_at')
     comment_form = CommentForm()
     context = {
         'ad': ad,
         'comments': comments,
         'comment_form': comment_form
     }
     return render(request, self.template_name, context)
Exemple #4
0
    def get(self, request, pk):
        ad = Ad.objects.get(id=pk)
        comments = Comment.objects.filter(ad=ad).order_by('-updated_at')
        comment_form = CommentForm()

        favorites = list()
        if request.user.is_authenticated:
            rows = request.user.favorite_ads.values('id')
            favorites = [row['id'] for row in rows]

        context = {
            'ad': ad,
            'comments': comments,
            'comment_form': comment_form,
            'favorites': favorites
        }
        return render(request, self.template_name, context)
Exemple #5
0
 def get(self, request, pk):
     x= Ad.objects.get(id=pk)
     comments = Comment.objects.filter(ad=x).order_by('-updated_at')
     comment_form = CommentForm()
     ctx = {'comments':comments, 'ad':x, 'comment_form':comment_form}
     return render(request, self.template_name, ctx)
Exemple #6
0
 def get(self, request, pk):
     a = Ad.objects.get(id=pk)
     comments = Comment.objects.filter(ad=a).order_by('-updated_at')
     comment_form = CommentForm()
     context = {'ad': a, 'comments': comments, 'comment_form': comment_form}
     return render(request, 'ads/ad_detail.html', context)