Skip to content
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

Propagate 'default' from model_field to serializer field. #9030

Merged
merged 10 commits into from
Aug 7, 2023
9 changes: 9 additions & 0 deletions docs/api-guide/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ When serializing the instance, default will be used if the object attribute or d

Note that setting a `default` value implies that the field is not required. Including both the `default` and `required` keyword arguments is invalid and will raise an error.

Notes Regarding default value propagation from model to serializer:

all the default values of model will be pass as default to serializer and to the options method.
auvipy marked this conversation as resolved.
Show resolved Hide resolved

if the default is callable then it is propagated in serializer which is evaluated at each time but
auvipy marked this conversation as resolved.
Show resolved Hide resolved
not in options method.
auvipy marked this conversation as resolved.
Show resolved Hide resolved
auvipy marked this conversation as resolved.
Show resolved Hide resolved

if the value for given field is not given then default value will be present in serializer also avaliable in serializer's methods.Specified validation on given field will be evaluted on default value as that field will be present in serializer.
auvipy marked this conversation as resolved.
Show resolved Hide resolved

### `allow_null`

Normally an error will be raised if `None` is passed to a serializer field. Set this keyword argument to `True` if `None` should be considered a valid value.
Expand Down