Guest User

Untitled

a guest
Oct 11th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. notify.py
  2.  
  3. def send_notification(data, user, req_user, email):
  4. channel_layer = get_channel_layer()
  5. group_name = 'user_id_{0}'.format(user.id)
  6. async_to_sync(channel_layer.group_send)(group_name,
  7. {
  8. "type": "notify",
  9. "text": data,
  10. },
  11. )
  12. if email:
  13. send_mail(subject='Уведомление', message=f"{data}", from_email=req_user.email,
  14. recipient_list=[user.email]) # from_email-от кого и recepient_list-кому
  15. notify = Notification.objects.create(sender=req_user, message=data)
  16. notify.receivers.add(user)
  17. notify.save()
Add Comment
Please, Sign In to add comment