title: Pass request context to serializer from Viewset in Django Rest Framework
body: <p>I have a case where the values for a serializer field depend on the identity of the currently logged in user.  I have seen how to add the user to the context when initializing a serializer, but I am not sure how to do this when using a ViewSet, as you only supply the serializer class and not the actual serializer instance.</p>
  
  <p>Basically I would like to know how to go from:</p>
  
  <pre><code>class myModelViewSet(ModelViewSet):
     queryset = myModel.objects.all()
     permission_classes = [DjangoModelPermissions]
     serializer_class = myModelSerializer
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>class myModelSerializer(serializers.ModelSerializer):
      uploaded_by = serializers.SerializerMethodField()
      special_field = serializers.SerializerMethodField()
  
      class Meta:
          model = myModel
  
      def get_special_field(self, obj):
          if self.context['request'].user.has_perm('something.add_something'):
             return something
  </code></pre>
  
  <p>Sorry if it wasn't clear, from the DOCs:
  <a href="http://www.django-rest-framework.org/api-guide/serializers/#including-extra-context">Adding Extra Context</a> 
  Which says to do </p>
  
  <pre><code>serializer = AccountSerializer(account, context={'request': request})
  serializer.data
  </code></pre>
  
  <p>But I am not sure how to do that automatically from the viewset, as I only can change the serializer class, and not the serializer instance itself.</p>