简体   繁体   中英

django-push-notifications in Django Rest Framework

I'm trying to use django-push-notifications library in my Django REST backend project. I have used Firebase Cloud Messaging. Here is the implementation;

settings.py

PUSH_NOTIFICATIONS_SETTINGS = {
    "FCM_API_KEY": "private key from FCM app"
}

views.py

user, created = User.objects.get_or_create(email=email, username=username)

if created:
    GCMDevice.objects.create(registration_id="token", cloud_message_type="FCM", user=user)

models.py

@receiver(post_save, sender=Action)
def create_new_action(sender, instance, created, **kwargs):
    if created:
        devices = GCMDevice.objects.filter(Q(user=instance.admin)|Q(user__in=instance.users.all()))
        msg = "New action is created in %s" % instance.name
        devices.send_message(msg)

My question is what should registration_id be while I'm creating the GCMDevice object for each registered user?

registration_id come from your frontend

actually you must have an api that get user(frontend) fcm token or get it(fcm token) in user registration or login api's

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM