使用django信号创建用户Feed [英] Creating user feed using django signals

查看:171
本文介绍了使用django信号创建用户Feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个我的模型创建一个其他模型的流。它工作正常。但是,现在我想让Feed用户具体。我使用django的预定义用户模型。有什么可能的方法?

This my model to create a stream of other models.Its working fine. But, now I want to make the feed user specific. I am using django's predefine User model . What are the possible ways to do that?

class StreamItem(models.Model):
      content_type = models.ForeignKey(ContentType)
      object_id = models.PositiveIntegerField()
      pub_date = models.DateTimeField()

      content_object = generic.GenericForeignKey('content_type', 'object_id')

      def get_rendered_html(self):
         template_name = 'streams/stream_item_%s.html' % (self.content_type.name)
         return render_to_string(template_name, { 'object': self.content_object })



def create_stream_item(sender, instance, signal, *args, **kwargs):
    # Check to see if the object was just created for the first time
    if 'created' in kwargs:
        if kwargs['created']:
            create = True

        # Get the instance's content type
        ctype = ContentType.objects.get_for_model(instance)

        pub_date = instance.pub_date

        if create:
            si = StreamItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date)``



# Send a signal on post_save for each of these models
for modelname in [Fest, College, Event]: 
    my_signal = dispatch.Signal()      
    my_signal.connect(create_stream_item, sender=modelname)


推荐答案

想尝试这个程序。

https:// django -activity-stream.readthedocs.org/en/latest/

它使用信号创建动作流。

It uses the signal to create the action stream.

这篇关于使用django信号创建用户Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆