title: Upload images inside nested serializers in django rest framework
body: <p>How can i upload images when user is trying to create announcement. I need to upload images to my computer and assign them to the announcement that he is trying to create.</p>
  <p>Models.py</p>
  <pre><code>class Announcement(models.Model):
      author = models.ForeignKey(User, on_delete=models.CASCADE)
      name = models.CharField(max_length=100)
      address = models.CharField(max_length=100)
      photo = models.ManyToManyField(Photo, blank=True)
  
  def nameFile(instance, filename):
      return '/'.join(['images', str(instance.name), filename])
  
  
  class Photo(models.Model):
      name = models.CharField(max_length=100)
      image = models.ImageField(upload_to=nameFile, blank=True, null=True)
  
  </code></pre>
  <p>Views.py</p>
  <pre><code>class AnnouncementCreate(CreateAPIView):
      permission_classes = [IsAuthenticated]
      queryset = models.Announcement.objects.all()
      serializer_class = AnnouncementSerializer
  
      def perform_create(self, serializer):
          serializer.save(author=self.request.user)
  
  class PhotoViewSet(ListAPIView):
  
      queryset = models.Photo.objects.all()
      serializer_class = PhotoSerializer
  
      def post(self, request, *args, **kwargs):
          file = request.data.get('image')
          image = models.Photo.objects.create(image=file)
          return HttpResponse(json.dumps({'message': &quot;Uploaded&quot;}), status=200)
  
  </code></pre>
  <p>Serializers.py</p>
  <pre><code>class AnnouncementSerializer(serializers.ModelSerializer):
      parameters = ParameterSerializer(many=True, required=False)
      photo = PhotoSerializer(many=True, required=False)
  
      class Meta:
          model = Announcement
          fields = ['id', 'name', 'address', 'date',
                    'price', 'description', 'author', 'parameters', 'photo']
  
  class PhotoSerializer(serializers.ModelSerializer):
      class Meta:
          model = Photo
          fields = ('name', 'image')
  
  </code></pre>