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
db7d15d5
Commit
db7d15d5
authored
Aug 23, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #181 from flashingpumpkin/master
Maintain a reference to the parent/root serializer
parents
acbc2d17
2f9775c1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
djangorestframework/resources.py
+1
-0
djangorestframework/serializer.py
+12
-3
No files found.
djangorestframework/resources.py
View file @
db7d15d5
...
@@ -169,6 +169,7 @@ class FormResource(Resource):
...
@@ -169,6 +169,7 @@ class FormResource(Resource):
)
)
# Add any unknown field errors
# Add any unknown field errors
if
not
self
.
allow_unknown_form_fields
:
for
key
in
unknown_fields
:
for
key
in
unknown_fields
:
field_errors
[
key
]
=
[
u'This field does not exist.'
]
field_errors
[
key
]
=
[
u'This field does not exist.'
]
...
...
djangorestframework/serializer.py
View file @
db7d15d5
...
@@ -97,6 +97,11 @@ class Serializer(object):
...
@@ -97,6 +97,11 @@ class Serializer(object):
The maximum depth to serialize to, or `None`.
The maximum depth to serialize to, or `None`.
"""
"""
parent
=
None
"""
A reference to the root serializer when descending down into fields.
"""
def
__init__
(
self
,
depth
=
None
,
stack
=
[],
**
kwargs
):
def
__init__
(
self
,
depth
=
None
,
stack
=
[],
**
kwargs
):
if
depth
is
not
None
:
if
depth
is
not
None
:
self
.
depth
=
depth
self
.
depth
=
depth
...
@@ -130,9 +135,12 @@ class Serializer(object):
...
@@ -130,9 +135,12 @@ class Serializer(object):
# If an element in `fields` is a 2-tuple of (str, tuple)
# If an element in `fields` is a 2-tuple of (str, tuple)
# then the second element of the tuple is the fields to
# then the second element of the tuple is the fields to
# set on the related serializer
# set on the related serializer
if
isinstance
(
info
,
(
list
,
tuple
)):
class
OnTheFlySerializer
(
self
.
__class__
):
class
OnTheFlySerializer
(
self
.
__class__
):
fields
=
info
fields
=
info
parent
=
getattr
(
self
,
'parent'
)
or
self
if
isinstance
(
info
,
(
list
,
tuple
)):
return
OnTheFlySerializer
return
OnTheFlySerializer
# If an element in `fields` is a 2-tuple of (str, Serializer)
# If an element in `fields` is a 2-tuple of (str, Serializer)
...
@@ -150,8 +158,9 @@ class Serializer(object):
...
@@ -150,8 +158,9 @@ class Serializer(object):
elif
isinstance
(
info
,
str
)
and
info
in
_serializers
:
elif
isinstance
(
info
,
str
)
and
info
in
_serializers
:
return
_serializers
[
info
]
return
_serializers
[
info
]
# Otherwise use `related_serializer` or fall back to `Serializer`
# Otherwise use `related_serializer` or fall back to
return
getattr
(
self
,
'related_serializer'
)
or
Serializer
# `OnTheFlySerializer` preserve custom serialization methods.
return
getattr
(
self
,
'related_serializer'
)
or
OnTheFlySerializer
def
serialize_key
(
self
,
key
):
def
serialize_key
(
self
,
key
):
"""
"""
...
...
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