Skip to content

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

Merged

Conversation

erickwilder
Copy link
Contributor

Please, refer to the #3937 for more information.

Add an usage example on how to pass a callable to the `Field.initial` in the docs.
@jpadilla
Copy link
Member

I think this is a great enhancement, thanks!

you may do with any regular Django `Field`:

def user_default_color():
return 'blue'
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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! :)

Copy link
Contributor Author

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.
@jpadilla
Copy link
Member

Looking good. @tomchristie any further comments?

@tomchristie
Copy link
Member

👍 Yup!

@tomchristie
Copy link
Member

@xordoquy - I'm a bit unclear on branching plans - should we merge this to master and re-milestone as 3.3.0?

@xordoquy
Copy link
Collaborator

@tomchristie will take some time tomorrow to add more information about branching.
Anything that goes into master will be for 3.4. I've opened a 3.3.x branch for the bug fixes only.

@jpadilla
Copy link
Member

@xordoquy ace, thanks!

jpadilla added a commit that referenced this pull request Feb 19, 2016
…tial-value

Closes #3937. Support callable as the value of `initial` for any `serializer.Field`
@jpadilla jpadilla merged commit 0b6f53e into encode:master Feb 19, 2016
@jpadilla
Copy link
Member

@erickwilder thanks for this! 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants