title: Django Rest Framework- can I allow pk id or full objects in a serializer's create method?
body: <p>Lets say I have the following models:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Author(models.Model):
      first_name = models.CharField(max_length=32)
      last_name = models.CharField(max_length=32)
  
  class Book(models.Model):
      title = models.CharField(max_length=64)
      author = models.ForeignKeyField(Author, on_delete=models.CASCADE)
  </code></pre>
  
  <p>And I have the following serializer:</p>
  
  <pre class="lang-py prettyprint-override"><code>class BookSerializer(serializers.ModelSerializer):
      class Meta:
          model = Book
          fields = ('id', 'title', 'author')
          read_only_fields = ('id')
  </code></pre>
  
  <p>If I then query my books, A book's data looks like:</p>
  
  <pre><code>{
      "id": 1,
      "title": "Book Title",
      "author": 4
  }
  </code></pre>
  
  <p>Which is what I want, as I return both an array of books, as well as an array of authors, and allow the client to join everything up.  This is because I have many authors that are repeated across books.</p>
  
  <p>However, I want to allow the client to either submit an existing author id to create a new book, or all of the data for a new author.  E.g.:</p>
  
  <p>Payload for new book with existing author:</p>
  
  <pre><code>{
      "title": "New Book!",
      "author": 7
  }
  </code></pre>
  
  <p>or, payload for a new book with a new author:</p>
  
  <pre><code>{
      "title": "New Book!",
      "author": {
          "first_name": "New",
          "last_name": "Author"
      }
  }
  </code></pre>
  
  <p>However the second version, will not pass the data validation step in my serializer.  Is there a way to override the validation step, to allow either an author id, or a full object?  Then in my serializer's create method, I can check the type, and either create a new author, get its id, and create the new book, or just attach the existing id.  Thoughts?</p>