New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SerializerMethodField also supporting a setter #2734
Comments
|
@maryokhin I get that, maybe my explanation is not very clear, what I would like to achieve is that there is also a setter available inside the It doesn't have to be the |
Ah, okay, I didn't understand the whole picture then. I would say that if you need both input and output for a field then the intent is cleaner to implement your own field with |
Seconding @maryokhin's comment above. |
"I would say that if you need both input and output for a field then the intent is cleaner to implement your own field with to_internal_value and to_representation" - or implement your own DRF :). I also need this feature. I can use setter (point |
Does not seem cleaner to me, especially, because I had to override
Usage example:
|
This is another implementation:
|
A good enhancement (in my opinion) will be a possibility to also have a setter in the
SerializerMethodField
.So of only having
get_<field_name>
an option to haveset_<field_name>
Proposed solution
Set it as a possible
kwarg
as insetter="set_something"
. When the SerializerMethodField'sto_internal_value
is fired it can check if thissetter
kwarg is set up and fire this function:Just an enhancement I thought would be nice to have, any thoughts?
The text was updated successfully, but these errors were encountered: