I am using Django's comments framework to manage comments in my website. I have custom comment model and form that extends Django's, as following:
Model:
class FTComment(Comment):
upvotes = models.PositiveSmallIntegerField()
downvotes = models.PositiveSmallIntegerField()
Form:
class FTCommentForm(CommentForm):
captcha = ReCaptchaField(required=True)
def get_comment_create_data(self):
# Use the data of the superclass, and remove extra fields
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)
FTCommentForm.base_fields.pop('url')
FTCommentForm.base_fields.pop('email')
FTCommentForm.base_fields.pop('name')
The comment form works fine, and browsing the database data in the SQLite Database Browser I can find it there:
So, why can't I get the list of comments? Is there something I'm missing? Here's the template:
{% load i18n %}
{% load comments %}
<link rel="stylesheet" type="text/css" href="/static/css/comment.css" />
<p>
<strong>{% trans "Comments" %}</strong>
</p>
<div class="comment_box">
{% if user.is_authenticated %}
{% render_comment_form for obj %}
{% else %}
<p>Please <a href="/login">log in</a> to leave a comment.</p>
{% endif %}
{% get_comment_count for obj as count %}
<p>Count: {{ count }}</p>
{% get_comment_list for obj as comments %}
{% for comment in comments %}
{{ comment.comment }}
{% endfor %}
</div>
count
returns 0, although there are 2 comments for this object in the database, and the for
loop renders nothing.
A help with this would be hugely appreciated.
Edit: View added
Here's the view of this case in particular:
def show_detail(request, img_id):
img = get_object_or_404(Image, pk=img_id)
img.views += 1
img.save()
try:
referer = Referer()
referer.referer_url = request.META['HTTP_REFERER']
referer.object = img
referer.save()
except KeyError:
pass
return render(request, "img/show_detail.html", {'img': img})
Edit 2:
I'm sorry, I should have explained. The templates which renders the comments is in a different file so it can be used by other pages/templates. The reference to the object is passed like this: {% include "comment/main.html" with obj=img %}
to this template.