Django GetStream和Django发表评论

时间:2015-12-17 19:37:22

标签: django django-models getstream-io

如何使用django_comments从Django GetStream保存活动,如何获取此数据?谢谢!

我用render_comment_form实现了Django注释,类似于https://django.readthedocs.org/en/1.4.X/ref/contrib/comments/,我想知道如何在GetStream中保存活动以及如何在保存之后进行咨询 谢谢你,但我有类似的东西:

from django.db import models
from fluent_comments.compat import CommentManager, Comment #, signals
from fluent_comments.models import FluentComment
from stream_django.activity import Activity
from stream_django import feed_manager
from django.db.models import signals
from publications.models import Ad

class ActivityComments(FluentComment, Activity):
    pass

    def __unicode__(self):
        #return "%s COMENTA-->> %s" % (self.user.first_name, self.object_content.item)
        return "%s COMENTA-->> %s" % (self.user.first_name, self.object_pk)

    @property
    def activity_object_attr(self):
        return self

    @property
    def activity_actor_attr(self):
        return self.user

    @property
    def activity_time(self):
        return self.created

    @property
    def extra_activity_data(self):
        return {'a': self.item}

    @property
    def activity_notify(self):
        if self.object_content.item.seller.user != self.user:
            target_feed = feed_manager.get_notification_feed(
                self.object_content.item.seller.user.id)
            return [target_feed]

    @classmethod
    def apply_activity_notify(cls, sender, instance, using, **kwargs):

        ad=Ad.objects.get(id=instance.object_pk)
        comment = FluentComment.objects.get(id=instance.id)
        comment.object_content = ad
        comment.activity_notify


"""
signals
"""

signals.post_save.connect(ActivityComments.apply_activity_notify, sender=Comment)

我知道我可以注册活动,但是当我去getstram管理员时,我什么也没做。另外,另一个问题是,当注册表已经完成时,我可以用它来获取活动吗?:

enricher = Enrich()
feed = feed_manager.get_feed('flat', user.id)
activities = feed.get(limit=3)['results']
I hope your answer, Thanks.

1 个答案:

答案 0 :(得分:0)

Django Comment允许您自定义用于存储注释的模型。

首先,您需要创建一个应用程序来保存Django Comment的自定义并将其添加到您的settings.py

INSTALLED_APPS = [
    ...
    'my_comment_app',
]

COMMENTS_APP = 'my_comment_app'

然后在my_comment_app / models.py中,您需要将您的评论模型注册为Stream活动。

from django.db import models
from django.contrib.comments.models import Comment
from stream_django.activity import Activity

class ActivityComment(Comment, Activity):
    pass

然后你需要将自定义应用程序注册到Django Comment,为此添加到my_comment_app / __ init__.py此代码

from my_comment_app.models import ActivityComment


def get_model():
    return ActivityComment