How I can make a notification system in Django by signals, in which any user add like to the video send a notification to the author who added like to his video, I tried everything and no thing worked with me
my model
class Video(models.Model):
author = models.ForeignKey(Account, on_delete=models.CASCADE)
video = models.FileField(upload_to='post-videos', validators=[validate_file_extension])
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=250, unique_for_date='publish')
is_public = models.BooleanField(default=False)
created_date = models.DateTimeField(auto_now_add=True)
likes = models.ManyToManyField(Account, blank=True, related_name='likes', default=None)
the signals file
@receiver(post_save, sender=Video.likes)
def update_likes(sender, instance, created, **kwargs):
if created == False:
instance.video.likes.save()
print('like updated!')
post_save.connect(update_likes, sender=Video)
the notification model that I tried to base on my notification but I filed then I try by signals
class Notification(models.Model):
NOTIFICATION_TYPE = ((1, 'like'))
video = models.ForeignKey("videos.Video", on_delete=models.CASCADE, related_name="noti_video", blank=True, null=True)
sender = models.ForeignKey(Account, on_delete=models.CASCADE, related_name="noti_from_user")
user = models.ForeignKey(Account, on_delete=models.CASCADE, related_name="noti_to_user")
notification_type = models.IntegerField(choices=NOTIFICATION_TYPE)
text_preview = models.CharField(max_length=90, blank=True)
date = models.DateTimeField(auto_now_add=True)
is_seen = models.BooleanField(default=False)