If user_data is validated_data, you can simply add kwarg 'context' to pass 
an extra data.
serializer = UserSerializer(data=user_data, context={'device_id': device_id

Inside UserSerializer, you can get device_id by 

Or you can use built-in method get_serializer_context in viewset.
def get_serializer_context(self):
    default return is
        'request': self.request,
        'format': self.format_kwarg,
        'view': self
    context = super(YourViewSet, self).get_serializer_context()
    # You can add what you want
    context['device_id'] = self.request.META.get('HTTP_DEVICEID', '')

if you override get_serializer_context, you must call serializer with 
get_serializer because get_serializer contains get_serializer_context 

class YourViewSet(viewsets.GenericViewSet):
    queryset = Foo.objects.all()
    serializer_class = UserSerializer

    def bar(self, request, *args, **kwargs)
        *serializer **= self.get_serializer(data=user_data)*

Now, You can get context in serializer.

# this also available because we pass request as context

Hope this could help you :)

You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to