Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@carltongibson
Copy link
Collaborator

Closes#2032closes#3066

Adds an example usingsource='*' 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.


The key points from the example, though, are:

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

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 entireDataPoint object, and must map from that

Copy link
CollaboratorAuthor

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
Contributor

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
CollaboratorAuthor

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. 😃

@carltongibsoncarltongibson merged commitcf3929d intoencode:masterDec 20, 2017
@carltongibsoncarltongibson deleted the 374/source-star-example branchDecember 20, 2017 09:04
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull requestNov 17, 2020
* Add example using `source=‘*’` to custom field docs.* Add nested serialiser exampleClosesencode#2032closesencode#3066
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lovelydinosaurlovelydinosaurlovelydinosaur left review comments

Assignees

No one assigned

Projects

None yet

Milestone

3.7.4 Release

Development

Successfully merging this pull request may close these issues.

Improvesource='*' documentation. More documentation on source='*' for Serializer fields

2 participants

@carltongibson@lovelydinosaur

[8]ページ先頭

©2009-2025 Movatter.jp