Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
4bc829d4
Commit
4bc829d4
authored
Dec 16, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1298 from craigds/fix-nested-serializers-with-renamed-fields
Fix nested serializers with renamed fields
parents
fc2dee84
4a134eef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletions
+28
-1
rest_framework/serializers.py
+3
-1
rest_framework/tests/test_serializer.py
+25
-0
No files found.
rest_framework/serializers.py
View file @
4bc829d4
...
...
@@ -422,7 +422,9 @@ class BaseSerializer(WritableField):
if
self
.
source
==
'*'
:
if
value
:
into
.
update
(
value
)
reverted_data
=
self
.
restore_fields
(
value
,
{})
if
not
self
.
_errors
:
into
.
update
(
reverted_data
)
else
:
if
value
in
(
None
,
''
):
into
[(
self
.
source
or
field_name
)]
=
None
...
...
rest_framework/tests/test_serializer.py
View file @
4bc829d4
...
...
@@ -105,6 +105,17 @@ class ModelSerializerWithNestedSerializer(serializers.ModelSerializer):
model
=
Person
class
NestedSerializerWithRenamedField
(
serializers
.
Serializer
):
renamed_info
=
serializers
.
Field
(
source
=
'info'
)
class
ModelSerializerWithNestedSerializerWithRenamedField
(
serializers
.
ModelSerializer
):
nested
=
NestedSerializerWithRenamedField
(
source
=
'*'
)
class
Meta
:
model
=
Person
class
PersonSerializerInvalidReadOnly
(
serializers
.
ModelSerializer
):
"""
Testing for #652.
...
...
@@ -456,6 +467,20 @@ class ValidationTests(TestCase):
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
def
test_writable_star_source_with_inner_source_fields
(
self
):
"""
Tests that a serializer with source="*" correctly expands the
it's fields into the outer serializer even if they have their
own 'source' parameters.
"""
serializer
=
ModelSerializerWithNestedSerializerWithRenamedField
(
data
=
{
'name'
:
'marko'
,
'nested'
:
{
'renamed_info'
:
'hi'
}},
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
self
.
assertEqual
(
serializer
.
errors
,
{})
class
CustomValidationTests
(
TestCase
):
class
CommentSerializerWithFieldValidator
(
CommentSerializer
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment