How to integrate notification feature to Custom User in Django

962 Views Asked by At

I have gone through many blogs and apps, mostly all the apps are integrating notifications feature using Django auth user, So if there is any way or blog for it that would be helpful.

Problem That i am facing is i have defined my user model as:

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)

And i want to add notification center to the existing model, so what could be the best way for it.

1

There are 1 best solutions below

1
On BEST ANSWER

Donot know why anybody didn't answered

You can use one that i recently used , its django-notification module and below is the snippet Handler:-

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)

generate an notification

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')

Read refs:-

Ref1 and Ref2