title: Get or create in Django Rest framework
body: <p>I want to have get_or_create funcionality when posting data to a model with foreign keys. None of the solutions I found had worked.</p>
  
  <p>I've tried to override create method.</p>
  
  <p>My Models:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Branch(models.Model):
      branch_name = models.CharField(max_length=30, primary_key=True)
  
  class Developer(models.Model):
      login = models.CharField(max_length=30, primary_key=True)
      name = models.CharField(max_length=30)
      email = models.EmailField()
  
  class Commit(models.Model):
      commit_id = models.CharField(max_length=40, primary_key=True)
      author = models.ForeignKey(Developer, on_delete=models.CASCADE)
      branch = models.ForeignKey(Branch, on_delete=models.CASCADE)
  </code></pre>
  
  <p>My serializers:</p>
  
  <pre class="lang-py prettyprint-override"><code>class BranchSerializer(serializers.ModelSerializer):
      class Meta:
          model = Branch
          fields = '__all__'
  
  class CommitSerializer(serializers.ModelSerializer):
      branch = BranchSerializer()
      author = DeveloperSerializer()
  
      class Meta:
          model = Commit
          fields = '__all__'
  
      def create(self, validated_data):
          branch_data = validated_data.pop('branch')
          author_data = validated_data.pop('author')
          branch, _ = Branch.objects.get_or_create(**branch_data)
          author, _ = Developer.objects.get_or_create(**author_data)
          return Commit.objects.create(branch=branch, author=author, **validated_data)
  </code></pre>
  
  <p>This works if none of the models instances exists in the database. However my solution fails if I try to post new commit to existing branch or using existing developer.</p>
  
  <p>Django Rest framework is responding with bad request message.</p>
  
  <p>I'm posting using curl and JSON.
  error from curl:</p>
  
  <pre class="lang-sh prettyprint-override"><code>{"branch":{"branch_name":["branch with this branch name already exists."]},"author":{"login":["develope
  r with this login already exists."]}}
  </code></pre>
  
  <p>error from django:</p>
  
  <pre class="lang-sh prettyprint-override"><code>Bad Request: /commits/
  </code></pre>