How do I implement FCM on Python?

421 Views Asked by At

This is my serializer class which consists of 2 tables i.e Server and Android .On the android table i have created a function that if both the labels (i.e label from Server and Android are same return label to new field i.e(return_label).Now all i want is to pass my return_label field to my android app using pusher.Help

from rest_framework import serializers
from .models import Server,Android
from pusher_push_notifications import  PushNotifications
from pusher import Pusher 
from django. shortcuts import render
from  rest_framework.response import Response
from  rest_framework import status


  #This is my Food Serializer
 class FoodSerializers(serializers.HyperlinkedModelSerializer):
        class Meta:
            model=Server
            fields=('labelServer','Image1','upload1','Ingredients')

   #Android Serializer
class AndroidSerializers(serializers.ModelSerializer):
          return_label =  serializers.SerializerMethodField()
           class Meta:
             model = Android
             fields = ('label', 'imagestring', 'return_label')



    #Compare label from Server and Android

  def get_return_label(self, obj):
         queryset = Server.objects.filter( labelServer=obj.label)
        queryset_serializer = FoodSerializers( queryset, many=True, read_only=True)      
        push_notify()
        return queryset_serializer.data

   #Push Notification code

  def push_notify(label,ingredients):
        pn_client=PushNotifications(instance_id='fa68a5f8-de2f-436d-9e76- 
        eec73dc7b10c',secret_key='A685761BD68E7A0157D7944A805EAFF7C56313823A835DA23DAC59B1076AAD0A')'                             '

response = pn_client.publish(
    interests=['hello'],
    publish_body={'apns': {'aps': {'alert': 'Food Compared!!'}},
                  'fcm': {'notification': {'title': 'label'+str(Server.label), 'body': 'Ingredients!'+str(Server.Ingredients)}}}
)

print(response['publishId'])
1

There are 1 best solutions below

0
On

I might be mistaken, but I'm fairly certain that Pusher and FCM are competing solutions. I think you will use one or the other, but not both.