0

这是我的序列化程序类,它包含 2 个表,即服务器和 Android。在 android 表上,我创建了一个函数,如果两个标签(即来自服务器和 Android 的标签相同,则将标签返回到新字段 ie( return_label)。现在所有我想要将我的return_label字段传递给我的 android 应用程序使用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'])
4

1 回答 1

0

我可能弄错了,但我相当肯定 Pusher 和 FCM 是相互竞争的解决方案。我认为您会使用其中一个,但不会同时使用两者。

于 2019-05-14T22:55:39.537 回答