title: "non_field_errors": [ "Invalid data. Expected a dictionary, but got list." ] in django rest framework while calling api in postman
body: <p>It was working fine when I created order object from orderitem objects using validated.pop() function. Now, I have another model for BillingDetails that needs to be created as well which has a foreign key to Order model.</p>
  <p>Now front end is sending chunks of data which contains orderitems data and also billingdetails at the same time. And I have to create Order object creating Orderitem objects and BillingDetails object at the same time.</p>
  <p>I have tried writing this but got error on api call on <strong>Postman.</strong></p>
  <p><a href="https://i.stack.imgur.com/PdMOF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PdMOF.jpg" alt="enter image description here" /></a></p>
  <p>My models:</p>
  <pre><code>class Order(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)    
      start_date = models.DateTimeField(auto_now_add=True)
      ordered_date = models.DateTimeField()
      ordered = models.BooleanField(default=False)   
      def __str__(self):
          return self.user.email
  
  class OrderItem(models.Model):    
      order = models.ForeignKey(Order,on_delete=models.CASCADE, blank=True,null=True,related_name='order_items')
      item = models.ForeignKey(Product, on_delete=models.CASCADE,blank=True, null=True)
      quantity = models.IntegerField(default=1)
  
  
      def __str__(self):
          return f&quot;{self.quantity} items of {self.item} of {self.order.user}&quot;
  
  
  class BillingDetails(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
      order = models.OneToOneField(Order, on_delete=models.CASCADE, blank=True, null=True, related_name='billing_details')
      first_name = models.CharField(max_length=50,blank=True,null=True)
      last_name = models.CharField(max_length=50, blank=True, null=True)
      email = models.EmailField(blank=True, null=True)
      phone = models.CharField(max_length=50,blank=True,null=True)
      country = models.CharField(max_length=50,blank=True,null=True)
      city = models.CharField(max_length=50,blank=True,null=True)
      address = models.CharField(max_length=100,blank=True,null=True)
      postal = models.CharField(max_length=50,blank=True,null=True)
  
      def __str__(self):
          return self.address
  </code></pre>
  <p>My view:</p>
  <pre><code>class AddtoOrderItemView(ListCreateAPIView):
      permission_classes = [IsAuthenticated]
      queryset = OrderItem.objects.all()
      serializer_class = OrderSerializer
  </code></pre>
  <p>My serializer (<strong>Initially</strong>):</p>
  <pre><code>class OrderSerializer(serializers.ModelSerializer):    
      order_items = OrderItemSerializer(many=True)
      user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
      class Meta:
          model = Order
          fields = ['id','user','start_date', 'ordered_date', 'ordered', 'order_items']
          # depth = 1
      
  
       def create(self, validated_data):
           user = self.context['request'].user
           order_items = validated_data.pop('order_items')
           order = Order.objects.create(user=user,**validated_data)
           for order_items in order_items:
               OrderItem.objects.create(order=order,**order_items)
           return order
  </code></pre>
  <p>It was working fine until now, I was able to order object while creating orderitems at the same time. Now when I popped billing deatils data and tried to create one, I got this <strong>Expected a dictionary, but got list.</strong> on Postman.</p>
  <p>My serializer (<strong>Now</strong>)</p>
  <pre><code>class OrderSerializer(serializers.ModelSerializer):
      billing_details = BillingDetailsSerializer(many=False)
      order_items = OrderItemSerializer(many=True)
      user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
      class Meta:
          model = Order
          fields = ['id','user','start_date', 'ordered_date', 'ordered', 'order_items','billing_details']
          # depth = 1
  
      
      def create(self, validated_data):
          user = self.context['request'].user
          order_items = validated_data.pop('order_items')
          billing_details = validated_data.pop('billing_details')
          order = Order.objects.create(user=user,**validated_data)
          BillingDetails.objects.create(user=user,**billing_details)
          for order_items in order_items:
              OrderItem.objects.create(order=order,**order_items)
          return order
  </code></pre>
  <p>How to resolve this??</p>