1

I've spent a bit of time digging around in django-fluent-comments recently. I know a little bit of django, but am completely stumped by how this package works.

Essentially, I don't understand where the actual query to get the comments for an object is made.

In the function 'FluentCommentsList(node)', the queryset containing the comments appears to come from this call on line 67:

comment_list = context['comment_list']'

I've no idea where the actual query to populate 'comment_list' is made though. It looks like the function get_comments_for_model in models.py might have something to do with this but I've tried to comment it out and the comments still appear on the page regardless.

Lastly, I don't understand how the foreign key relationship to user works. In the database user_id on comments is a foreign key to the user model, but when I changed FluentCommentsList as so:

class FluentCommentsList(Node):
    def render(self, context):
        coms = context['comment_list']
        for c in coms:
            print c.user_id.user_picture

This results in the error below where it seems what should be a user model is interpreted as a long.

'long' object has no attribute 'user_picture'

Any chance someone could explain what's happening please? All I'm really trying to do is access the user_picture field via the foreign key to user but it would also be really good to understand the code a bit better.

Thanks a lot,

rix
  • 10,104
  • 14
  • 65
  • 92

1 Answers1

2

Django-fluent-comments uses the default Django Comment model in django.contrib.comments. The FluentCommentsList you see is actually a template tag that recieves a context from the calling template - including a comment_list or target_object_id if you want the tag to work.

Each Comment includes a ForeignKey to a user. The reason you get an error is because you try to access a field on user_id, not on user. If your User model includes a user_picture field, the following should work:

coms = context['comment_list']
for c in coms:
    print c.user.user_picture
knbk
  • 52,111
  • 9
  • 124
  • 122
  • Ah ok, so a stupid mistake then. Thanks a lot for pointing this out. However, now I have this part working I still need to modify the original query which gets the comments so i can add a prefetch related and avoid triggering a lookup on each comment to get the profile picture. Any idea where that happens, it looks like it has to be the query i pointed out but modifying it appears to change nothing. Any ideas? – rix Mar 24 '14 at 09:16
  • Got this figured out now, it gets it from comments app. Thanks for the answer have accepted as it helped me a lot at the time.. – rix Mar 24 '14 at 14:04
  • How to remove for comment-date and that? Means how to modify the way how comment is getting displayed after posting immediately. – cold_coder Dec 03 '15 at 10:57