django-push-notifications icon indicating copy to clipboard operation
django-push-notifications copied to clipboard

How to use this library, noob here

Open notrealanurag opened this issue 5 years ago • 1 comments
trafficstars

Hey there, I am a beginner so please forgive me if I sound silly. I am trying to make a Rest API using DRF and am using serializers for connecting the models and retrieving the data in ReactJS using the fetch method. I wanted to have the functionality of push notifications, and use the data of the different models in the notifications. I read the documentation and but was not able to figure anything out.

Any suggestions?

notrealanurag avatar Apr 02 '20 18:04 notrealanurag

how far did you get?

you'll have to trudge through the django docs yourself but with DRF you can make a relatively simple GET/POST/DELETE viewset along these lines in your views.py

from rest_framework import generics
from rest_framework import mixins
from rest_framework import permissions

from rest_framework.serializers import CurrentUserDefault

class APNSDeviceSerializer(serializers.ModelSerializer):
    name = serializers.CharField(blank=True, null=True)
    active = serializers.BooleanField(default=True)
    device_id = serializers.UUIDField(required=True)
    registration_id = serializers.CharField(max_length=200)
    user = serializers.HiddenField(default=CurrentUserDefault())

    class Meta:
        model = APNSDevice

class DeviceViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.DeleteModelMixin):
    serializer_class = APNSDeviceSerializer
    permission_classes = [permissions.IsAuthenticated]
    
    def get_queryset(self):
        return self.request.user.apnsdevice_set.all()

dashdanw avatar Jun 07 '20 20:06 dashdanw