title: How to save multiple videos and images in Django Rest Framework?
body: <p>I am creating a Django based web application, where <code>Post</code> Model will have multiple images and videos. I want to upload those multiple images in images model and videos in video model</p>
  <pre class="lang-py prettyprint-override"><code># models.py
  #Post Model
  class Post(models.Model):
      # Owner / user
      user = models.ForeignKey(to=User, on_delete=models.CASCADE)
      caption = models.CharField(max_length=64, verbose_name='Post Caption')
      body = models.CharField(max_length=1024, verbose_name='Post Body')
  
      def __str__(self):
          return self.user.email
  
      def get_author(self):
          return self.user.email
  
  class Image(models.Model):
      
      post = models.OneToOneField(to=Post, on_delete=models.CASCADE)
      image = models.ImageField()
  
  class Video(models.Model):
      
      post = models.OneToOneField(to=Post, on_delete=models.CASCADE)
      image = models.FileField()    
  
  </code></pre>
  <pre class="lang-py prettyprint-override"><code># serializers.py
  class PropertySerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = Property
          fields = '__all__'
  
      def create(self, validated_data):
          media_files = self.context.get('view').request.FILES
          post = Property.objects.create(
              **validated_data
              )
          for file in media_files.values():
              &quot;&quot;&quot;
              if file is video:
                    then file will be saved in video model 
              if file is image:
                    then file will be saved in image model
              How to do it?
              &quot;&quot;&quot;
              
  </code></pre>
  <p>And how to validate if files are only image or video. If someone post any other things except image or video then it will give validation error. Is there any good way to it?</p>