title: Validating a foreign key field in a serializer django rest framework
body: <p>I am using django rest framework and have a html form which sends data to the rest api. I am doing a serializer.is_valid check and save() on the request data.
  In the the front end form I have an ID field which is a foreign key in the serializer's model. And when serializer.is_valid is run, it throws an error that says the foreign key object is missing. To overcome this I am trying to get the Foreign key object instance using the id from the input html form and insert it in the serializer data.</p>
  
  <p>I have written a definition validate_ in my serializer and I am assuming it to run(as per this tutorial - <a href="http://www.django-rest-framework.org/api-guide/serializers/#validation" rel="nofollow">http://www.django-rest-framework.org/api-guide/serializers/#validation</a>) when serializer.is_valid() is executed. But this definition is not being executed. Appreciate help.</p>
  
  <pre><code>class TeamViewSet(viewsets.ModelViewSet):
      serializer_class = TeamSerializer
      queryset = Team.objects.all()
      def create(self, request, *args, **kwargs):
  
          permission_classes = (
              permissions.IsAuthenticated
          )
          serializer = self.get_serializer(data=request.data)
          serializer.is_valid()
  
  
          return Response(.....)
  </code></pre>
  
  <h1>Serializer</h1>
  
  <pre><code>class TeamSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Team
          fields = ('id','name','description','leader')
  
      def validate_leader(self, leader_id):
          try:
              data = Leaders.objects.get(id=leader_id)
          except Exception as e:
              raise ValidationError(....)
          return data
  </code></pre>