i have this blog site,i want to return all acvtive comments associated to a post.
def post_detail(request,year, month,day, post):
post = get_object_or_404(Post,status=Post.Status.PUBLISHED,slug=post,publish__year=year,publish__month=month,publish__day=day)
#list of active comments for this post
comments = post.comments.filter(active=True)
#form for users to comment
form = CommentForm()
#List of similar posts
post_tags_ids = post.tags.values_list('id',flat=True)
similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
[:4]
return render(request,'blog/post/detail.html',{'post':post,'comments':comments,'form':form})
Its returning null response,
>Solution :
probably you should continue to filter the simmilar_post variable
def post_detail(request,year, month,day, post):
post= get_object_or_404(Post,status=Post.Status.PUBLISHED,slug=post,publish__year=year,publish__month=month,publish__day=day)
#list of active comments for this post
comments = post.comments.filter(active=True)
#form for users to comment
form = CommentForm()
#List of similar posts
post_tags_ids = post.tags.values_list('id',flat=True)
similar_posts =
Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
similar_posts =
similar_posts.annotate(same_tags=Count('tags')).order_by('-same_tags','-
publish')
return render(request,'blog/post/detail.html',{'post':post,'comments':comments,'form':form,
'similar_posts':similar_posts})