0

我浏览了许多博客和应用程序,大多数应用程序都使用 Django auth 用户集成通知功能,所以如果有任何方法或博客对它有帮助。

我面临的问题是我将我的用户模型定义为:

class user_signup(models.Model):
    full_name = models.CharField('Full Name',max_length=200)
    user_email = models.EmailField('User Email', max_length=255)
    user_password = models.CharField('Password', max_length=30)
    date_time=models.DateTimeField(auto_now=True)
    def __unicode__(self):
        return smart_unicode(self.user_email)

而且我想将通知中心添加到现有模型中,那么最好的方法是什么。

4

1 回答 1

0

不知道为什么没人回答

您可以使用我最近使用的一个,它的 django-notification 模块,下面是代码片段 处理程序:-

from django.db.models.signals import post_save
from notifications.signals import notify
from myapp.models import MyModel

def my_handler(sender, instance, created, **kwargs):
    notify.send(instance, verb='was saved')

post_save.connect(my_handler, sender=MyModel)

生成通知

from notifications.signals import notify

notify.send(user, recipient=user, verb='you reached level 10')

// "recipient" can also be a Group, the notification will be sent to all the Users in the Group
notify.send(comment.user, recipient=group, verb=u'replied', action_object=comment,
            description=comment.comment, target=comment.content_object)

notify.send(follow_instance.user, recipient=follow_instance.follow_object, verb=u'has followed you',
            action_object=instance, description=u'', target=follow_instance.follow_object, level='success')

阅读参考文献:-

参考 1参考 2

于 2016-09-30T06:49:37.200 回答