tomchristie/django-rest-framework — pull request #1306 by kevmo314 (2013-12-20 11:50:17+00:00)
Title: Add write_only_fields support

I was surprised to find that there wasn't any built-in support for write-only fields. I needed a field that I could validate, but didn't store or read from. For instance, when taking a password confirmation field. I put it in `serializers.Serializer` instead of `serializers.ModelSerializer` because this can be used completely independent of any model as well.

Thus, I added the functionality. It doesn't pass the field on to the model when saving (obviously), but it permits you to use `validate_` functions. Example usage:

```
class ProfileSerializer(serializers.Serializer):
class Meta:
write_only_fields = ('current_password','password')
email = serializers.CharField(required=False)
password = serializers.CharField(required=False)
current_password = serializers.CharField()

def validate_current_password(self, attrs, source):
if self.object is None:
return attrs
u = authenticate(username=self.object.user.email, password=attrs[source])
if u is not None:
return attrs
else:
raise serializers.ValidationError('Error!')
```