code: def send_messages(self, request, queryset, bulk=False, data=False):
          
          ret = []
          errors = []
          total_failure = 0
  
          for device in queryset:
              if bulk:
                  if data:
                      response = queryset.send_message(
                          data={"Nick": "Mario"}
                      )
                  else:
                      response = queryset.send_message(
                          title="Test notification",
                          body="Test bulk notification"
                      )
              else:
                  if data:
                      response = device.send_message(data={"Nick": "Mario"})
                  else:
                      response = device.send_message(
                          title="Test notification",
                          body="Test single notification"
                      )
              if response:
                  ret.append(response)
  
              failure = int(response['failure'])
              total_failure += failure
              errors.append(str(response))
  
              if bulk:
                  break
  
          if ret:
              if errors:
                  msg = _("Some messages were sent: %s" % (ret))
              else:
                  msg = _("All messages were sent: %s" % (ret))
              self.message_user(request, msg)
  
          if total_failure > 0:
              self.message_user(
                  request,
                  _("Some messages failed to send. %d devices were marked as "
                    "inactive." % total_failure),
                  level=messages.WARNING
              )
docs: Provides error handling for DeviceAdmin send_message and
          send_bulk_message methods.