Advertisement
genkid123

Untitled

Oct 12th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. Ошибка AttributeError at /api/v1/applicant/applicants/
  2. 'list' object has no attribute 'id' Возникает когда в вызове ложу скобки []
  3. Код
  4. def send_notification(data, user, req_user, email):
  5. channel_layer = get_channel_layer()
  6. group_name = 'user_id_{0}'.format(user.id)
  7. print(group_name)
  8. for group in group_name:
  9. async_to_sync(channel_layer.group_send)(group,
  10. {
  11. "type": "notify",
  12. "text": data,
  13. },
  14. )
  15. if email:
  16. send_mail(subject='Уведомление', message=f"{data}", from_email=req_user.email,
  17. recipient_list=[user.email]) # from_email-от кого и recepient_list-кому
  18. notify = Notification.objects.create(sender=req_user, message=data)
  19. notify.receivers.add(user)
  20. notify.save()
  21. Вызов
  22. applicant1 = User.objects.all().get(username="applicant1")
  23. applicant2 = User.objects.all().get(username="applicant0")
  24. notify_text = 'SomeMessageforGroup'
  25. send_notification(notify_text, user=[applicant1, applicant2], req_user=user_id,
  26. email=False)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement