Django Comment Notification

I am using Django contrib.comments and want to know the following.

Are there any utilities or applications that can be connected to the application that sends you a notification when a comment is sent on an item?

I didn’t work very much with signals, so please be a little descriptive.

Here is what I came up with.

from django.contrib.comments.signals import comment_was_posted
from django.core.mail import send_mail

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

def comment_notification(request):
    user = request.user
    message = "123"
    notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)
+3
source share
3 answers

Connect django.contrib.comments.signals.comment_was_postedto if necessary.notification .models.send()

+3
source

You need to register the function comment_notificationwith a signal comment_was_posted.

from django.contrib.comments.signals import comment_was_posted

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def comment_notification(sender, comment, request):
        user = request.user
        message = "123"
        notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)
+2

I don’t know about the application (I’m pretty sure that something will be there), but it’s quite simple to collapse my own. You can click a button Comment comment_was_postedto call a function that will send you an email.

0
source

Source: https://habr.com/ru/post/1766770/


All Articles