title: Django Rest Framework - Check Password to Validate Form
body: <p>I'm trying to validate a form through DRF, but it would require the user to enter their password for confirmation. I can't seem to get it to work. Here is my current View and Serializer. Its for a 'change email' form, two fields required, the email and user password. It's for a seperate email model. The serializer:</p>
  
  <pre><code>class UpdateEmailAddressSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = EmailAddress
          fields = ('email',)
  </code></pre>
  
  <p>And the APIView:</p>
  
  <pre><code>class UpdateEmailAPI(APIView):
  
  permission_classes = (IsAuthenticated,)
  serializer_class = UpdateEmailAddressSerializer
  
  def post(self, request, user, format=None):
      user = User.objects.get(username=user)
      serializer = UpdateEmailAddressSerializer(data=request.data, instance=user)
      if serializer.is_valid():
  
          ## logic to check and send email
  
          serializer.save()
          return Response(serializer.data, status=status.HTTP_201_CREATED)
  
      else:
              return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)  
  </code></pre>
  
  <p>I'm not sure where to place the password or what to do with it. Its from the User model itself. When I attempted to add password to the fields in the UpdateEmail serializer it ended up updating the User password with plain text and making that user object unable to use that password.</p>
  
  <p>I just want to check the password of the user for confirmation of this form. Is there an obvious way to do this?</p>
  
  <h2>EDIT</h2>
  
  <p>When I attempt to bring 'password' into the serializer, an error tells "Field name <code>password</code> is not valid for model <code>EmailAddress</code>." So when I attempt to bring it in e.g.</p>
  
  <pre><code>password = serializers.CharField(required=True)
  </code></pre>
  
  <p>or try:</p>
  
  <pre><code>## UserPasswordSerializer 
  class UserPasswordSerializer(serializers.ModelSerializer):
  
  class Meta:
      model = User
      fields = (
          'password',
          )
  
  ## In UpdateEmailAddressSerializer
  password = UserPasswordSerializer()
  </code></pre>
  
  <p>I get this error when submitting the form on DRF:</p>
  
  <blockquote>
    <p>Got AttributeError when attempting to get a value for field 
        <code>password</code> on serializer <code>UpdateEmailAddressSerializer</code>. The 
        serializer field might be named incorrectly and not match any 
        attribute or key on the <code>EmailAddress</code> instance. Original exception 
        text was: 'EmailAddress' object has no attribute 'password'</p>
  </blockquote>
  
  <p>So it seems to be telling me password isn't part of EmailAddress model which is correct. But I cant figure out how to simply check the password alongside the form post without making it part of EmailAddress.</p>