Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Return all active comment in a post

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,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading