Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add write_only_fields support #1306
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
Thus, I added the functionality. It doesn't pass the field on to the model when saving (obviously), but it permits you to use
Hiya @kevmo314, thanks for the input.
Write-only fields have come up before, see https://groups.google.com/d/msg/django-rest-framework/UxWRbNE9NyU/s38xVmh6sw0J and https://groups.google.com/d/msg/django-rest-framework/abMsDCYbBRg/_T0zoHcDonIJ although I'm not sure if your behaviour (don't save the field) is exactly the same as the use cases mentioned in those threads (do save the field, just don't ever output it).
This sort of thing is currently something I'd rather see provided for by third party packages - for exmple, since there are at least a couple of different write-only styles the user might want. The contributing docs give some guidelines on packaging third party apps, and I'd be very happy to see this packaged up and linked to from the main docs. Failing a proper PyPI package, you could also publish this on https://djangosnippets.org/ which we could also then link to from the main docs.
Thanks again for the contribution.