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
ea9a3d88
Commit
ea9a3d88
authored
May 18, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #859 from craigds/master
fix for #765
parents
80a26008
208bd991
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
rest_framework/serializers.py
+4
-0
rest_framework/tests/serializer.py
+22
-0
No files found.
rest_framework/serializers.py
View file @
ea9a3d88
...
@@ -378,6 +378,10 @@ class BaseSerializer(WritableField):
...
@@ -378,6 +378,10 @@ class BaseSerializer(WritableField):
# Set the serializer object if it exists
# Set the serializer object if it exists
obj
=
getattr
(
self
.
parent
.
object
,
field_name
)
if
self
.
parent
.
object
else
None
obj
=
getattr
(
self
.
parent
.
object
,
field_name
)
if
self
.
parent
.
object
else
None
if
self
.
source
==
'*'
:
if
value
:
into
.
update
(
value
)
else
:
if
value
in
(
None
,
''
):
if
value
in
(
None
,
''
):
into
[(
self
.
source
or
field_name
)]
=
None
into
[(
self
.
source
or
field_name
)]
=
None
else
:
else
:
...
...
rest_framework/tests/serializer.py
View file @
ea9a3d88
...
@@ -91,6 +91,17 @@ class PersonSerializer(serializers.ModelSerializer):
...
@@ -91,6 +91,17 @@ class PersonSerializer(serializers.ModelSerializer):
read_only_fields
=
(
'age'
,)
read_only_fields
=
(
'age'
,)
class
NestedSerializer
(
serializers
.
Serializer
):
info
=
serializers
.
Field
()
class
ModelSerializerWithNestedSerializer
(
serializers
.
ModelSerializer
):
nested
=
NestedSerializer
(
source
=
'*'
)
class
Meta
:
model
=
Person
class
PersonSerializerInvalidReadOnly
(
serializers
.
ModelSerializer
):
class
PersonSerializerInvalidReadOnly
(
serializers
.
ModelSerializer
):
"""
"""
Testing for #652.
Testing for #652.
...
@@ -418,6 +429,17 @@ class ValidationTests(TestCase):
...
@@ -418,6 +429,17 @@ class ValidationTests(TestCase):
except
:
except
:
self
.
fail
(
'Wrong exception type thrown.'
)
self
.
fail
(
'Wrong exception type thrown.'
)
def
test_writable_star_source_on_nested_serializer
(
self
):
"""
Assert that a nested serializer instantiated with source='*' correctly
expands the data into the outer serializer.
"""
serializer
=
ModelSerializerWithNestedSerializer
(
data
=
{
'name'
:
'marko'
,
'nested'
:
{
'info'
:
'hi'
}},
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
class
CustomValidationTests
(
TestCase
):
class
CustomValidationTests
(
TestCase
):
class
CommentSerializerWithFieldValidator
(
CommentSerializer
):
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