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

Add example using source=‘*’ to custom field docs. #5688

Merged
merged 3 commits into from Dec 20, 2017

Conversation

carltongibson
Copy link
Collaborator

@carltongibson carltongibson commented Dec 19, 2017

Closes #2032 closes #3066

Adds an example using source='*' to create a nested representation from a flat object.

Need to explain how this interacts with non-read_only fields, and describe why a dictionary is expected from to_internal_value in that case. — #3066 (comment)

Does that.

@carltongibson carltongibson added this to the v3.7.4 milestone Dec 19, 2017
@carltongibson carltongibson requested a review from tomchristie Dec 19, 2017

The key points from the example, though, are:

* `to_representation` is passed the entire `DataPoint` object must map from that
Copy link
Member

@tomchristie tomchristie Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_representation is passed the entire DataPoint object , and must map from that

Copy link
Collaborator Author

@carltongibson carltongibson Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Note that this example doesn't handle validation. Partly for that reason, in a
real project, the coordinate nesting might be better handled with a nested serialiser using two
`IntegerField` instances, each with `source='*'`.
Copy link
Member

@tomchristie tomchristie Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it'd be worth us demonstrating this at the end of this new section.
source='*' is confusing to folks, so hammering home how to use it in non-custom-fields too might be helpful?

Copy link
Collaborator Author

@carltongibson carltongibson Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I can add that example. 😃

@carltongibson carltongibson merged commit cf3929d into encode:master Dec 20, 2017
1 check passed
@carltongibson carltongibson deleted the 374/source-star-example branch Dec 20, 2017
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Add example using `source=‘*’` to custom field docs.
* Add nested serialiser example

Closes encode#2032 closes encode#3066
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.

Improve source='*' documentation. More documentation on source='*' for Serializer fields
2 participants