title: How do I save an object using serializer from another serializer in django rest?
body: <p>I have two models, a parent and it's items</p>
  
  <pre><code>class Parent(models.Model):
      #fields
  
  class ParentItems(models.Model):
      parentId = #parentId
      #fields
  </code></pre>
  
  <p>and want to create method <strong>POST</strong> <code>parent/</code> with ParentItems included, like</p>
  
  <pre><code>{
      "parentField": "value",
      "parentItems": [
          {
              "parentItemsField": "value"
          }
      ]
  }
  </code></pre>
  
  <p>So  I create <code>Parent</code> view using <code>ModelViewSet</code> and then the serializer:</p>
  
  <pre><code>class ParentItemSerializer(serializers.ModelSerializer):
      #serializer
  
  class ParentSerializer(serializers.ModelSerializer):
      parentItems = ParentItemSerializer(many=True, required=True, write_only=True)
  
      def _createParentItems(self, parentItem, parent):
          for item in parentItem:
              item['parent'] = parent.id
              parentItemSerializer = ParentItemSerializer(data=item)
              if parentItemSerializer.is_valid(raise_exception=True):
                  itemSerializer.save()
  
      def create(self, validated_data):
          with transaction.atomic():
              parentItems = validated_data.pop('parentItems')
              createdData = super(ParentSerializer, self).create(validated_data)
              # create the parent item
              self._createParentItems(parentItems, createdData)
              return createdData
  </code></pre>
  
  <p>I add <code>parentItems</code> field in <code>ParentSerializer</code>, inside the <code>create</code> method I pop the <code>parentItems</code> and pass it into <code>_createParentItems</code> to create the items. </p>
  
  <p>but this doesn't work, the parentItems is already an object. when I call <code>parentItemSerializer.is_valid(raise_exception=True)</code> it errors. </p>
  
  <p>How do I save an object from another serializer in django rest? 
  should I use another serializer field? </p>
  
  <p>Tried using OrderedDict, it doesn't work, it didn't pass the items to <code>validated_data</code></p>