Django get_comment_list returns empty list

398 views Asked by At

I've been pulling my hair out over this and can't figure out what's going on.

In my view I can do this:

from django.contrib.comments import Comment

...
context['comments'] = Comment.objects.filter(object_pk = self.kwargs['pk'])

...

Then in my template when I do:

{% for comment in comments %}
{{ comment.comment }}
{% endfor %}

It works perfectly and displays each comment...

However when I try to use the django template tags for comments I get an empty list

{% load comments %}
{% get_comment_list for video as comments %}
{% for comment in comments %}
{{ comment.comment }}
{% endfor %}
{{ comment_list|length }}  // displays '0'

video in the above code is the object instance in the template context - I use it elsewhere in the template and it works fine - ie {{ video.title }}, {{ video.id }}

Also - other comment template tags seem to work fine:

{% render_comment_list video %}

displays the test template I have located at comments/list.html - this template just prints out "hello world".

Any idea what's going on here or how to debug it?

1

There are 1 answers

0
Timmy O'Mahony On

Just a guess but, when you do this:

Comment.objects.filter(object_pk = self.kwargs['pk'])

in the view, you aren't specifying a content_type (Video) for the comments you wish to get, so you are retrieving all comments for any object with the id 'pk' - maybe that's why you are seeing comments when you do it manually, but none when you leave it up to the template tag. Maybe the comments aren't attached to the correct ContentType - you could check this in the django admin