title: Avoid nested objects when using nested serializers
body: <p>I have two models, one contains the other in a foreignKey relationship, I wanted to make an API that would return the combine of these two models, so I attempted to use nested Serializers to add the related model as well, but the data are not all on the same level, the related models is a object inside the first.</p>
  
  <p>Here are the Models</p>
  
  <pre class="lang-py prettyprint-override"><code>class ModelOne(models.Model):
      last_counter = models.IntegerField()
  
  
  class ModelTwo(models.Model):
      model_one = models.ForeignKey(ModelOne, on_delete=models.CASCADE)
      category = models.CharField(max_length=64)
      counter_type = models.CharField(max_length=32)
  </code></pre>
  
  <p>Here are the serializers</p>
  
  <pre class="lang-py prettyprint-override"><code>class ModelOneSerializer(serializers.ModelSerializer):
      class Meta:
          model = ModelOne
          fields = "__all__"
  
  
  class ModelTwoSerializer(serializers.ModelSerializer):
      model_one= ModelOneSerializer(read_only=True)
  
      class Meta:
          model = ModelTwo
          fields = "__all__"
  </code></pre>
  
  <p>This would return from the API in the form of</p>
  
  <pre><code>{
     "category" : ...,
     "counter_type" : ...,
     "model_one" : {
       "last_counter" : ...
     }
  }
  </code></pre>
  
  <p>But I <strong>don't</strong> want the response to be like that, I want it more like this</p>
  
  <pre><code>{
     "category" : ...,
     "counter_type" : ...,
     "last_counter" : ...,
  }
  </code></pre>
  
  <p>Is there a way to achieve this through serializers?</p>