title: Post request Manytomany field DRF with postman
body: <p>Objective: Creating a new entry in database from Postman using the &quot;POST&quot;.</p>
  <p>I am trying to send the data from Postman and I am using nested serializing. I have changed the create method i have shared the snippet below. Also, I tried this <a href="https://stackoverflow.com/questions/31276326/drf-post-to-manytomany-field">solution</a> but it did not work. Can someone please point out the mistake I am making?</p>
  <p>When I am trying to post as form-data the error is <code>{&quot;magazine&quot;:[&quot;This field is required.&quot;]}</code>.
  When I am trying to post it as raw data the error is <code>Direct assignment to the forward side of a many-to-many set is prohibited. Use magazine.set() instead.</code></p>
  <p>Here is my models:</p>
  <pre><code>class Article(models.Model):
      title = models.CharField(max_length=100)
      content = models.TextField()
      author = models.ForeignKey('authors.Author', on_delete=models.CASCADE)
      magazine = models.ManyToManyField('articles.Magazine')
  
      def __str__(self):
          return self.title
  
  
  class Magazine(models.Model):
      name = models.CharField(max_length=30)
      title = models.CharField(max_length=100)
  
      def __str__(self):
          return self.name
  </code></pre>
  <p>This is my serializers:</p>
  <pre><code>class MagazineSerializer(serializers.ModelSerializer):
      class Meta:
          model = Magazine
          fields = '__all__'
  
  class ArticleSerializer(serializers.ModelSerializer):
      author = AuthorSerializer(read_only=True, many=False)
      magazine = MagazineSerializer(many=True)
      class Meta:
          model = Article
          fields = [
              'title',
              'content',
              'author',
              'magazine',
          ]
  
      def create(self, validated_data):
          allmags = []
          magazine = validated_data.pop('magazine')
          for i in magazine:
              if Magazine.objects.get(id=magazine[&quot;id&quot;]).exists():
                  mags = Magazine.objects.get(id=magazine[&quot;id&quot;])
                  allmags.append(mags)
              else:
                  return Response({&quot;Error&quot;:  &quot;No such magazine exists&quot;}, status=status.HTTP_400_BAD_REQUEST)
              
          validated_data['author'] = self.context['request'].user
          validated_data['magazine'] = allmags
          return Article.objects.create(**validated_data)
  </code></pre>
  <p>Here is my view:</p>
  <pre><code>class ArticleViewSet(viewsets.ModelViewSet):
      queryset = Article.objects.all()
      serializer_class = ArticleSerializer
  
  class MagazineViewSet(viewsets.ModelViewSet):
      queryset = Magazine.objects.all()
      serializer_class = MagazineSerializer
  
      serializer_action_class = {
          'get_articles': MagazineSerializer,
      }
  
      @action(detail=True, url_path='articles', url_name='articles')
      def get_articles(self, request, pk=None):
          articles = Article.objects.filter(magazine=self.kwargs.get('pk'))
          serializer = ArticleSerializer(articles, many=True)
          return Response(serializer.data, status=200)
  </code></pre>
  <p>This is how I tried sending data as raw:</p>
  <pre><code>{
      &quot;title&quot;: &quot;New Post form Postman&quot;,
      &quot;content&quot;: &quot;Postman content new&quot;,
      &quot;magazine&quot;: [
          {
              &quot;id&quot;: 1,
              &quot;name&quot;: &quot;The Times&quot;,
              &quot;title&quot;: &quot;All News&quot;
          }
      ]
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/CFfSH.png" rel="nofollow noreferrer">This is how I posted as form-data:</a></p>