title: "Expected a list of items but got type \"str\"." in django rest framework
body: <p>I have an addproduct api in which frontend is sending a formdata in a post axios call. Formdata is used because there is an image field that need to be sent.</p>
  <p>But I got the following error.</p>
  <p><strong>&quot;Expected a list of items but got type &quot;str&quot;.&quot; in django rest framework.</strong></p>
  <p>The data is sent in the following form as shown below.</p>
  <p>{</p>
  <pre><code>        &quot;merchant&quot;: 8,
          &quot;category&quot;: &quot;[3,4]&quot;,
          &quot;brand&quot;:2,
          &quot;name&quot;:&quot;pvahnjjthhgjhtest&quot;,
          &quot;best_seller&quot;:true,
          &quot;top_rated&quot;:false,        
          &quot;collection&quot;:2,
          &quot;description&quot;:&quot;abc&quot;,
          &quot;featured&quot;: false,            
          &quot;availability&quot;: &quot;in_stock&quot;,
          &quot;warranty&quot;: &quot;no_warranty&quot;,
          &quot;rating&quot;:5,
          &quot;main_product_image&quot;:null,            
          &quot;services&quot;: &quot;cash_on_delivery&quot;,
          &quot;variants&quot;: &quot;[1,2]&quot;
      }
  </code></pre>
  <p>Here the main issue is on category and on variants.The error is also shown in these two fields. Since frontend is sending formdata, these two fields are sent as string. Now how can I handle these two fields on backend?? What I need is get 1 and 2 as pk .</p>
  <p><strong>How to get pks from the string. I tried json.load but it doenst work.</strong></p>
  <p>My models:</p>
  <pre><code>class Variants(models.Model):
      
      product_id = models.CharField(max_length=70, default='OAXWRTZ_12C',blank=True)
      price = models.DecimalField(decimal_places=2, max_digits=20,default=500)
      size = models.CharField(max_length=50, choices=SIZE, default='not applicable',blank=True,null=True)
      color = models.CharField(max_length=70, default=&quot;not applicable&quot;,blank=True,null=True)
      variant_image = models.ImageField(upload_to=&quot;products/images&quot;, blank=True,null=True)
      thumbnail = ImageSpecField(source='variant_image',
                                 processors=[ResizeToFill(100, 50)],
                                 format='JPEG',
                                 options={'quality': 60})
      quantity = models.IntegerField(default=10,blank=True,null=True)  # available quantity of given product
      variant_availability = models.CharField(max_length=70, choices=AVAILABILITY, default='available')
  
      class Meta:
          verbose_name_plural = &quot;Variants&quot;
  
      def __str__(self):
          return self.product_id
  </code></pre>
  <p>#Product Model</p>
  <pre><code>class Product(models.Model):
     
      merchant = models.ForeignKey(Seller,on_delete=models.CASCADE,blank=True,null=True)
      category = models.ManyToManyField(Category, blank=False)
      sub_category = models.ForeignKey(Subcategory, on_delete=models.CASCADE,blank=True,null=True)
      brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
      collection = models.ForeignKey(Collection, on_delete=models.CASCADE)
      featured = models.BooleanField(default=False)  # is product featured?
      best_seller = models.BooleanField(default=False)
      top_rated = models.BooleanField(default=False)
      tags = TaggableManager(blank=True)  # tags mechanism
      name = models.CharField(max_length=150,unique=True)
      main_product_image = models.ImageField(upload_to=&quot;products/images&quot;, null=True, blank=True)
      thumbnail = ImageSpecField(source='main_product_image',
                                 processors=[ResizeToFill(100, 50)],
                                 format='JPEG',
                                 options={'quality': 60})
      slug = models.SlugField(max_length=200,blank=True)       
      description = RichTextField(blank=True)
      #picture = models.ImageField(upload_to=&quot;products/images&quot;, null=True, blank=True)
      picture = models.ManyToManyField(ImageBucket,null=True,blank=True,verbose_name=&quot;Add extra 3 images&quot;)
      rating = models.IntegerField(choices=((1, 1),
                                                 (2, 2),
                                                 (3, 3),
                                                 (4, 4),
                                                 (5, 5))
                                        )
      availability = models.CharField(max_length=70, choices=AVAILABILITY, default='in_stock')
      warranty = models.CharField(max_length=100, choices=WARRANTY, default='no_warranty')
      services = models.CharField(max_length=100, choices=SERVICES, default='cash_on_delivery')
      variants = models.ManyToManyField(Variants,related_name='products')
  </code></pre>
  <p>My view:</p>
  <pre><code>class ProductAddAPIView(APIView):
      permission_classes = [IsAuthenticated]
  
      def post(self,request,*args,**kwargs):
          serializer = AddProductSerializer(data=request.data)
          if serializer.is_valid():
              return Response(serializer.data,{
                  &quot;message&quot;:&quot;Product has been created&quot;
              })
          return Response(serializer.errors)
  </code></pre>
  <p><strong>Update on the code:</strong></p>
  <p><strong>The data is now being sent in the following way:</strong></p>
  <pre><code>name: TestNamae
  category[0]: 7
  category[1]: 23
  brand: 7
  collection: 11
  availability: in_stock
  warranty: no_warranty
  service: cash_on_delivery
  rating: 3
  best_seller: true
  top_rated: true
  featured: true
  main_product_image: (binary)
  merchant: 2
  variants[0][product_id]: fgfdg
  variants[0][price]: 127
  variants[0][quantity]: 1
  variants[0][color]: red
  variants[0][size]: M
  variants[0][variant_availability]: not_available
  variants[0][variant_image]: (binary)
  variants[1][product_id]: fgfdg
  variants[1][price]: 127
  variants[1][quantity]: 1
  variants[1][color]: red
  variants[1][size]: M
  variants[1][variant_availability]: not_available
  variants[1][variant_image]: (binary)
  </code></pre>
  <p>But when sent like this, it says the category is required but when it is sent in a list [1,2] it works. The data needs to be sent in this way, because there are image field inside the array so Multipart form is to be used.</p>
  <p>How to solve this??</p>