title: Optional Nested relationships in Django Rest Framework?
body: <p>I want to create a serializer/view that accepts these both jsons:</p>
  <pre><code>{
      &quot;foo&quot;: &quot;bar&quot;,
      &quot;foobar&quot;: &quot;bazz&quot;,
      &quot;info&quot;: [
          {
              &quot;field&quot;: &quot;value&quot;,
              &quot;field2&quot;: &quot;value2&quot;
          }
      ]
  }
  </code></pre>
  <p>and</p>
  <pre><code>{
      &quot;foo&quot;: &quot;bar&quot;,
      &quot;foobar&quot;: &quot;bazz&quot;,
  }
  </code></pre>
  <p>Where the &quot;info&quot; node is optional.</p>
  <p>Right now I tried:</p>
  <ol>
  <li>Defining the nested relation as &quot;required=False&quot;</li>
  <li>Extending the simpler serializer.</li>
  </ol>
  <p>Both solutions didn't work. That meaning that default &quot;is_valid()&quot; doesn't work for both jsons.</p>
  <p>There's any way of doing so in a DRY way?</p>
  <h3>Edit, adding some code:</h3>
  <p>I'm extending APIView for the view, and serializers.Serializer for the Serializer, there's just not much code available to show.</p>
  <pre><code>class InfoSerializer(serializer.Serializer):
      field = serializer.CharField()
      field2 = serializer.Charfield()
  
  class FooBarSerializer(serializer.Serializer):
      foo = serializer.CharField()
      foobar = serializer.CharField()
      info = InfoSerializer(many=True, required=False)
  </code></pre>
  <p>and for the view:</p>
  <pre><code>class FooBarView(APIView):
      
       def post(self, request, format=None):
           data = FooBarSerializer(request.DATA)
           if data.is_valid():
               return Response(&quot;{'response': 'valid'}&quot;)
           return Response(&quot;{'response': 'invalid'}&quot;)
  </code></pre>