Как интегрировать функцию уведомлений в Custom User в Django

Я просмотрел множество блогов и приложений, в основном все приложения интегрировали функцию уведомлений с использованием аутентификации Django, поэтому, если есть какой-либо способ или блог для этого, это было бы полезно.

Проблема, с которой я сталкиваюсь, я определил мою модель пользователя как:

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)

И я хочу добавить центр уведомлений к существующей модели, так что может быть лучшим способом для этого.

1 ответ

Решение

Не знаю, почему никто не ответил

Вы можете использовать тот, который я недавно использовал, его модуль 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 и Ref2

Другие вопросы по тегам