title: How to set nested object in django rest framework?
body: <p>first of all, this is not about creating or updating nesting objects, but only about setting them. lets use the following example: I have the following models:</p>
  
  <pre><code>class Category(models.Model):
      code= models.CharField(max_length=2)
      name= models.CharField(max_length=100)
  
  class Question(models.Model):
      category= models.ForeignKey(Category, related_name='categories')
      title = models.CharField(max_length=100)
  </code></pre>
  
  <p>and the following serializers:</p>
  
  <pre><code>class CategorySerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Category
          fields = ('code', 'name')
  
  class QuestionSerializer(serializers.ModelSerializer):
      category= CategorySerializer()
  
      class Meta:
          model = Question
          fields = ('category', 'title')
  </code></pre>
  
  <p>Now, when I <code>get</code> a <code>Question</code>, its fine working as expected : I get the question fields with he category fields as expected.</p>
  
  <p>The problem that I have is when I want to <code>post</code> a <code>Question</code> only having the <code>Category.code</code>, I am not really sure how to set/use an existing <code>Category</code>. I have been trying different ways, but none of them worked.</p>
  
  <p>If I remove <code>category= CategorySerializer()</code> on the <code>QuestionSerializer</code> and I pass the <code>id</code> (<code>pk</code>) of the <code>Category</code> in my request, than it is working, the <code>Question</code> is saved with the related <code>Category</code>.</p>
  
  <p>Is there any way to indicate how to serialize the nested object?</p>
  
  <p>Thank you in advance for any comment/advise/solution.</p>