如何将通知功能集成到 Django 中的自定义用户

How to integrate notification feature to Custom User in Django

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

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

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)

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

不知道为什么没有人回答

你可以使用我最近使用的一个,它的 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')

阅读参考:-

Ref1 and Ref2