문제

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,

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top