Right now my I am triggering two type of signals.
type1 : If someone comment on author post then it will notify to author.
type2 if someone add reply on any parent comment and parent user id didn’t match with parent comment id then it will notify to parent user.
Now I am thinking to triggering signals for child object. Let you explain. User A comment “hello world” where hello world is an parent comment. Now user B add reply on user A comment then user C come and add reply on user B comment. Now I want to triggers signals for user B and notify to user B that an reply added from user C .
models.py
class BlogComment(models.Model):
blog = models.ForeignKey(Blog,on_delete=models.CASCADE,null=True, blank=True,related_name="blogcomment_blog")
parent = models.ForeignKey('self', on_delete=models.CASCADE,
null=True, blank=True, related_name='children')
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='user_comment',blank=True,null=True)
#my others model fields....
@receiver(post_save,sender=BlogComment)
def NotiFicationSignals(instance,created,**kwargs):
if created:
if instance.user.id != instance.blog.author.id: #send notification to author
noti_to_author = Notifications.objects.create(duplicate_value="author",blog=instance.blog,blogcomment=instance,sender=instance.user,receiver=instance.blog.author,text_preview=f"Recived new comment from {instance.user}")
#Notify to parent commenter. This will prevent to create notification if parent owner add reply on his own parent commnet.
if instance.parent and instance.parent.user.id != instance.user.id:
noti_to_commenter = Notifications.objects.create(duplicate_value="commenter",blog=instance.blog,blogcomment=instance,sender=instance.user,receiver=instance.parent.user,text_preview=f"{instance.user.first_name} replied on your comment")
type3 signals will notify to child user( user B )