Closed nishantkr18 closed 3 years ago
Create a new endpoint for user to update their own device token:
def get_device_type(ua):
"""
Parses HTTP User-Agent header string to return the device type.
Arguments:
ua {str} -- The User-Agent header value from HTTP request
Returns:
One of the following:
and
ios
web
"""
ua = ua.lower()
# TODO: Write the logic to get device type from HTTP User Agent (like below)
if 'android' in ua:
return Device.DEVICE_ANDROID
class DeviceSerializer(serializers.ModelSerializer):
class Meta:
model = Device
fields = ('device_type', 'device_token')
read_only_fields = ('device_type', )
class DetailDevice(generics.RetrieveUpdateAPIView):
"""
Update the Device token linked with given AuthToken
"""
serializer_class = DeviceSerializer
permission_classes = (IsAuthenticated, )
def get_object(self):
user = self.request.user
device_type = get_device_type(self.request.META.get('HTTP_USER_AGENT', 'web'))
return get_object_or_404(Device, user=user, device_type=device_type)
@nishantwrp @krashish8 here's the Django model you'll need to store FCM tokens