title: Django REST Framework how to specify error code when raising validation error in serializer
body: <p>I have an API endpoint that allow users to register an account. I would like to return HTTP 409 instead of 400 for a duplicate username.</p>
  
  <p>Here is my serializer:</p>
  
  <pre><code>from django.contrib.auth.models import User
  from rest_framework.serializers import ModelSerializer
  
  class UserSerializer(ModelSerializer):
      username = CharField()
  
      def validate_username(self, value):
          if User.objects.filter(username=value).exists():
              raise NameDuplicationError()
          return value
  
  
  class NameDuplicationError(APIException):
      status_code = status.HTTP_409_CONFLICT
      default_detail = u'Duplicate Username'
  </code></pre>
  
  <p>When the error is triggered, the response is: <code>{"detail":"Duplicate Username"}</code>. I realised that if I subclass APIException, the key <code>detail</code> is used instead of <code>username</code>.</p>
  
  <p>I want to have this response instead <code>{"username":"Duplicate Username"}</code></p>
  
  <p>or I would like to specify a status code when raising a ValidationError:</p>
  
  <pre><code>def validate_username(self, value):
      if User.objects.filter(username=value).exists():
          raise serializers.ValidationError('Duplicate Username', 
                                            status_code=status.HTTP_409_CONFLICT)
      return value
  </code></pre>
  
  <p>But this does not work as <code>ValidationError</code> only returns 400.</p>
  
  <p>Is there any other way to accomplish this?</p>