-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Closes #3937. Support callable as the value of initial
for any serializer.Field
#3943
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
Closes #3937. Support callable as the value of initial
for any serializer.Field
#3943
Conversation
…y `serializer.Field`
Add an usage example on how to pass a callable to the `Field.initial` in the docs.
I think this is a great enhancement, thanks! |
you may do with any regular Django `Field`: | ||
|
||
def user_default_color(): | ||
return 'blue' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have an example that makes a bit more sense.
I can only think of date/time examples - are there an other obvious use cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the date/time example is fine. Other use cases are possible but I think they'll make it more difficult to the reader to understand. Also, the example from the official Django docs[1] uses date/time too.
[1] https://docs.djangoproject.com/en/1.9/ref/forms/fields/#initial
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great - let's do the same! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @tomchristie
I've updated the docs. May you take a look?
Just like regular Django fields, the example adopted uses a `datetiume.date.today` to illustrate the functionality.
Looking good. @tomchristie any further comments? |
👍 Yup! |
@xordoquy - I'm a bit unclear on branching plans - should we merge this to master and re-milestone as 3.3.0? |
@tomchristie will take some time tomorrow to add more information about branching. |
@xordoquy ace, thanks! |
…tial-value Closes #3937. Support callable as the value of `initial` for any `serializer.Field`
@erickwilder thanks for this! 🎆 |
Please, refer to the #3937 for more information.