Skip to content

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
Contributor

I think this is a great enhancement, thanks!

you may do with any regular Django `Field`:

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

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
Contributor

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
Contributor

Looking good. @tomchristie any further comments?

@lovelydinosaur
Copy link
Contributor

👍 Yup!

@lovelydinosaur
Copy link
Contributor

@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
Contributor

@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
Contributor

@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
Contributor

@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