Skip to content

Commit

Permalink
feat: adding created_post and created_like function to signals.py in …
Browse files Browse the repository at this point in the history
…user app

1. created_post:
if post has been created this signal is run
and by using the action method in actstream created an activity with verb and object
Example: reza upload new post

2. created_like:
if user liked a post this signal has been run and created an activity with verb and object
Example: reza liked example post
  • Loading branch information
rzashakeri committed Jul 22, 2022
1 parent ba4c054 commit 30991f8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions post/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db.models.signals import post_save
from actstream import action
from django.dispatch import receiver

from comment.models import Comment
from post.models import Post, PostLike


@receiver(post_save, sender=Post)
def created_post(sender, instance, created, **kwargs):
"""
if post has been created this signal is run
and by using the action method in actstream created an activity with verb and object
Example: reza upload new post
"""
if created:
action.send(instance.user, verb="upload new post", action_object=instance)


@receiver(post_save, sender=PostLike)
def created_like(sender, instance, created, **kwargs):
"""
if user liked a post this signal has been run and created an activity with verb and object
Example: reza liked example post
"""
if created:
action.send(
instance.user, verb="liked", action_object=instance, target=instance.post
)

0 comments on commit 30991f8

Please sign in to comment.