您可以通过扩展 AbstactFCMDevice 类来定义您的自定义 FCMDevice 类,如下所示:
from fcm_django.models import AbstractFCMDevice
from django.db import models
class CustomFCMDevice(AbstractFCMDevice):
language = models.CharField(max_length=35, blank=False)
position = models.CharField(max_length=35, blank=False)
app_version = models.CharField(max_length=35, blank=False)
...
..
然后您可以使用您的自定义类来获取您的查询集:
from custom_fcm_django.models import CustomFCMDevice
device = CustomFCMDevice.objects.all().first()
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})
您可以使用 django rest framework APIView 来创建您的 API 端点,例如:
from rest_framework.views import APIView
class FCMDevicesListAPIView(APIView):
permission_classes = (IsAuthenticated, )
def get(self, request):
queryset = CustomFCMDevice.objects.all()
serializer = FCMDeviceSerializer(queryset, many=True)
return Response(serializer.data)