Implementing notifications with Django Restframework

1.3k views Asked by At

I have developed an api for mobile app which uses Django rest framework as backend. Now I want to create notification to user. Whenever new lesson is added by admin, logged in user will have a notification.

Here is a lesson model

class Lesson(models.Model):
    course = models.ForeignKey(Course, related_name='lcourse', on_delete=models.CASCADE, 
  null=True, blank=True)
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    image = models.ImageField(upload_to='lesson/', null=True, blank=True)


    def __str__(self):
        return self.name 
1

There are 1 answers

0
AudioBubble On

Try this:

pip install pyfcm

OR

pip install git+git://github.com/olucurious/PyFCM.git

Example:

# Send to single device.
from pyfcm import FCMNotification

push_service = FCMNotification(api_key="<api-key>")

registration_id = "<device registration_id>"
message_title = "Uber update"
message_body = "Hi john, your customized news for today is ready"
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)

# Send to multiple devices by passing a list of ids.
registration_ids = ["<device registration_id 1>", "<device registration_id 2>", ...]
message_title = "Uber update"
message_body = "Hope you're having fun this weekend, don't forget to check today's news"
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body)

print result

You just need to use firebase. Get api key from their and your device_registration_id or device_token and your are all done.

For more you can follow the following link