title: How to create a new user with django rest framework and custom user model
body: <p>I have a custom user model and I am using django-rest-framework to create API</p>
  
  <p>models.py:</p>
  
  <pre><code>class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(
          unique=True,
          max_length=254,
      )
      first_name = models.CharField(max_length=15)
      last_name = models.CharField(max_length=15)
      mobile = models.IntegerField(unique=True)
      date_joined = models.DateTimeField(default=timezone.now)
      is_active = models.BooleanField(default=True)
      is_admin = models.BooleanField(default=False)
  </code></pre>
  
  <p>serializers.py:</p>
  
  <pre><code>class UserSerializer(serializers.ModelSerializer):
      password1 = serializers.CharField(write_only=True)
      password2 = serializers.CharField(write_only=True)
  
      class Meta:
          model = User
          fields = ('first_name', 'last_name', 'email', 'mobile', 'password1', 'password2')
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>@api_view(['POST'])
  @permission_classes((AllowAny,))
  def create_user(request):
      serialized = UserSerializer(data=request.data)
      if serialized.is_valid():
          User.objects.create_user(
              serialized.save()
          )
          return Response(serialized.data, status=status.HTTP_201_CREATED)
      else:
          return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>However, when I try to create a new user I am getting this error:</p>
  
  <blockquote>
    <p>Got a <code>TypeError</code> when calling <code>User.objects.create()</code>. This may be because you have a writable field on the serializer class that is not a valid argument to <code>User.objects.create()</code>. You may need to make the field read-only, or override the UserSerializer.create() method to handle this correctly.</p>
  </blockquote>
  
  <p>This maybe because there's no password1 or password2 fields in the User model. But so, how can I create an API to create a new user using django-rest-framework?</p>