title: How to add additional data before serializer validation/save in DRF?
body: <p>So I have this class:</p>
  
  <pre><code>class MyClass(models.Model):    
      name = models.CharField(max_length=100)    
      created_time = models.DateTimeField(auto_now_add = True)
      modified_time = models.DateTimeField(auto_now = True)
  </code></pre>
  
  <p>and then other class representing related photos to MyClass:</p>
  
  <pre><code>class MyPhoto(models.Model):
      myclass = models.ForeignKey(MyClass, unique=False, related_name='photos')
      photo = models.ImageField(upload_to='photos',blank=False)
  </code></pre>
  
  <p>I would like to create an endpoint, which will handle photo uploads (content type will be multipart and id of associted myclass will be passed in url), so this is what I have:</p>
  
  <p>urls.py:</p>
  
  <pre><code>router = routers.DefaultRouter()    
  router.register(r'photos/(?P&lt;myclass_id&gt;\d+)',PhotoViewSet)
  </code></pre>
  
  <p>viewset:</p>
  
  <pre><code>class PhotoViewSet(CreateModelMixin,
                      viewsets.GenericViewSet):
      queryset = MyPhoto.objects.all()
      serializer_class = serializers.PhotoAlterSerializer
      parser_classes = (parsers.MultiPartParser,)
  
      def create(self, request, *args,**kwargs):
          myclass = MyClass.objects.get(pk=kwargs['myclass_id'])
          serializer = serializers.PhotoAlterSerializer(data=request.data,context={'request': request})
          if serializer.is_valid(raise_exception=True):
              photo=serializer.save(myclass=myclass)
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>and serializer:</p>
  
  <pre><code>class PhotoAlterSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = MyPhoto
          fields = ('myclass','photo')
  </code></pre>
  
  <p>as you can see Im adding additional attribute myclass to the serializer.save(myclass=myclass) method.</p>
  
  <p>However if I upload photo and correctly pass myclass id in url, I get <strong>This field is required.</strong> error. If I add correct hyperlink to the myclass into uploaded multipart form with photo, request will pass validation and then myclass from form will be replaced by myclass I got from url id.</p>
  
  <p>How can I make this work, so if I post only photo to the url <a href="http://blabla/api/photos/2" rel="nofollow">http://blabla/api/photos/2</a> the instance of this photo and myclass with pk=2 will be saved to db?</p>