title: How to post nested arrays in Django REST Framework with Postman form-data?
body: <p>I have a nested writable serializer with array fields. I need to test it with form-data because one of the field type is <code>ImageField</code>. When I changed the <code>ImageField</code> into <code>CharField</code> it worked fine if I posted it with raw JSON format.<br>
  My simplified <code>serializers.py</code>:  </p>
  
  <pre><code>class ProductMarketSerializer(serializers.ModelSerializer):
      id = serializers.IntegerField(required=False)
      market = serializers.PrimaryKeyRelatedField(many=False, queryset=Market.objects.all())
      slabs = serializers.PrimaryKeyRelatedField(many=True, queryset=Slab.objects.all())
      thicknesses = serializers.PrimaryKeyRelatedField(many=True, queryset=Thickness.objects.all())
      finish_types = serializers.PrimaryKeyRelatedField(many=True, queryset=FinishType.objects.all())
  
      class Meta:
          model = ProductMarket
          fields = ['id', 'market', 'name', 'slabs', 'thicknesses', 'finish_types']
  
  
  class ProductSerializer(serializers.ModelSerializer):
      collection = serializers.PrimaryKeyRelatedField(queryset=ProductCollection.objects.all(), many=False)
      color = serializers.PrimaryKeyRelatedField(queryset=ColorParent.objects.all(), many=False)
      images = ProductImageSerializer(many=True)
      descriptions = ProductDescriptionSerializer(many=True)
      markets = ProductMarketSerializer(many=True)
  
      class Meta:
          model = Product
          fields = ['id', 'product_code', 'collection', 'color', 'images', 'descriptions', 'markets', 'video', 'status']
  
      def create(self, validated_data):
          image_data = validated_data.pop('images')
          description_data = validated_data.pop('descriptions')
          market_data = validated_data.pop('markets')
  
          images = []
          for image in image_data:
              img_obj = ProductImage.objects.create(**image)
              images.append(img_obj)
  
          descriptions = []
          for description in description_data:
              desc_obj = ProductDescription.objects.create(**description)
              descriptions.append(desc_obj)
  
          markets = []
          for market in market_data:
              slabs = market.pop('slabs')
              thicknesses = market.pop('thicknesses')
              finish_types = market.pop('finish_types')
              market_obj = ProductMarket.objects.create(**market)
              market_obj.slabs.set(slabs)
              market_obj.thicknesses.set(thicknesses)
              market_obj.finish_types.set(finish_types)
              markets.append(market_obj)
  
          product = Product.objects.create(**validated_data)
          product.images.set(images)
          product.descriptions.set(descriptions)
          product.markets.set(markets)
  
          return product
  </code></pre>
  
  <p><code>views.py</code>:  </p>
  
  <pre><code>class ProductView(viewsets.ModelViewSet):
      permission_classes = [permissions.DjangoModelPermissions]
      serializer_class = ProductSerializer
      queryset = Product.objects.all()
  </code></pre>
  
  <p>For now I can only send 1 <code>slabs</code>, <code>thicknesses</code>, and <code>finish_types</code> each within 1 <code>markets</code> field. How to add another <code>slabs</code>, <code>thicknesses</code>, and <code>finish_types</code> for the same <code>markets</code>? What's the correct key-value pair format if I use form-data as Body?<br>
  <a href="https://i.stack.imgur.com/uNjPw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uNjPw.png" alt="enter image description here"></a><br>
  The created <code>Product</code> object:</p>
  
  <pre><code>{
      "message": "success",
      "data": {
          "id": 60,
          "product_code": "BQ1010",
          "collection": 1,
          "color": 1,
          "images": [
              {
                  "id": 57,
                  "image": "image",
                  "default": false
              }
          ],
          "descriptions": [
              {
                  "id": 65,
                  "language": 1,
                  "description": "new description in english"
              }
          ],
          "markets": [
              {
                  "id": 47,
                  "market": 1,
                  "name": "White Stone",
                  "slabs": [
                      1
                  ],
                  "thicknesses": [
                      2
                  ],
                  "finish_types": [
                      1
                  ]
              }
          ],
          "video": "https://www.youtube.com",
          "status": "Continue"
      }
  }
  </code></pre>
  
  <p>When I try to add the second <code>slabs</code> and <code>thicknesses</code> like this: 
  <a href="https://i.stack.imgur.com/k5Luz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k5Luz.png" alt="enter image description here"></a><br>
  The <code>slabs</code> and <code>thicknesses</code> fields will be empty.  </p>
  
  <pre><code> "markets": [
              {
                  "id": 48,
                  "market": 1,
                  "name": "White Stone",
                  "slabs": [],
                  "thicknesses": [],
                  "finish_types": [
                      1
                  ]
              }
          ],
  </code></pre>