How to delete notification by using django-notifications-hq

Viewed 138

How can we query and select specific id of a notification..?

Right now following problem i'm facing... You can see in else section i am sending notification that a person followed other person. Now In if selection when a person unfollow the person he followed. That notification should be removed so that when he follow again the previous notification get removes and new one get generated. I expect kind and help full ans from you guys . Thank you !:)

if follower:
        profile_.follower.remove(follower.id)
        actor = User.objects.get(pk=user_id)
        user = User.objects.get(username=username_to_toggle)
        query = Notification.objects.filter(id__in=notificacion_ids).update(deleted=True) #notificacion_ids(I don't understand how to get that.)
        print(query,"hey heyh eh")
        # json_follower = some_view(user)
    else:
        new_follower = User.objects.get(username__iexact=username_to_toggle)
        profile_.follower.add(new_follower.id)
        actor = User.objects.get(pk=user_id)
        user = User.objects.get(username=username_to_toggle)
        notify.send(actor, recipient=user, verb='follow you')
        # json_follower = some_view(username_to_toggle)
        is_following = True  
1 Answers

you would then filter the notifications model using the 'actor' and the 'recipient'. Something like this:

notification_ids =Notification.objects.filter(actor_object_id=actor.id,recipient_id=user.id).values_list('id', flat=True)
Related