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
49fae230
Commit
49fae230
authored
Nov 05, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass through kwargs to both Serializer and ListSerializer
parent
d048d328
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
rest_framework/relations.py
+10
-4
rest_framework/serializers.py
+11
-3
No files found.
rest_framework/relations.py
View file @
49fae230
...
@@ -13,6 +13,11 @@ class PKOnlyObject(object):
...
@@ -13,6 +13,11 @@ class PKOnlyObject(object):
def
__init__
(
self
,
pk
):
def
__init__
(
self
,
pk
):
self
.
pk
=
pk
self
.
pk
=
pk
MANY_RELATION_KWARGS
=
(
'read_only'
,
'write_only'
,
'required'
,
'default'
,
'initial'
,
'source'
,
'label'
,
'help_text'
,
'style'
,
'error_messages'
)
class
RelatedField
(
Field
):
class
RelatedField
(
Field
):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
...
@@ -31,10 +36,11 @@ class RelatedField(Field):
...
@@ -31,10 +36,11 @@ class RelatedField(Field):
# We override this method in order to automagically create
# We override this method in order to automagically create
# `ManyRelation` classes instead when `many=True` is set.
# `ManyRelation` classes instead when `many=True` is set.
if
kwargs
.
pop
(
'many'
,
False
):
if
kwargs
.
pop
(
'many'
,
False
):
return
ManyRelation
(
list_kwargs
=
{
'child_relation'
:
cls
(
*
args
,
**
kwargs
)}
child_relation
=
cls
(
*
args
,
**
kwargs
),
for
key
in
kwargs
.
keys
():
read_only
=
kwargs
.
get
(
'read_only'
,
False
)
if
key
in
MANY_RELATION_KWARGS
:
)
list_kwargs
[
key
]
=
kwargs
[
key
]
return
ManyRelation
(
**
list_kwargs
)
return
super
(
RelatedField
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
return
super
(
RelatedField
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
def
run_validation
(
self
,
data
=
empty
):
def
run_validation
(
self
,
data
=
empty
):
...
...
rest_framework/serializers.py
View file @
49fae230
...
@@ -43,6 +43,12 @@ import warnings
...
@@ -43,6 +43,12 @@ import warnings
from
rest_framework.relations
import
*
# NOQA
from
rest_framework.relations
import
*
# NOQA
from
rest_framework.fields
import
*
# NOQA
from
rest_framework.fields
import
*
# NOQA
LIST_SERIALIZER_KWARGS
=
(
'read_only'
,
'write_only'
,
'required'
,
'default'
,
'initial'
,
'source'
,
'label'
,
'help_text'
,
'style'
,
'error_messages'
,
'instance'
,
'data'
,
'partial'
,
'context'
)
# BaseSerializer
# BaseSerializer
# --------------
# --------------
...
@@ -52,7 +58,6 @@ class BaseSerializer(Field):
...
@@ -52,7 +58,6 @@ class BaseSerializer(Field):
The BaseSerializer class provides a minimal class which may be used
The BaseSerializer class provides a minimal class which may be used
for writing custom serializer implementations.
for writing custom serializer implementations.
"""
"""
def
__init__
(
self
,
instance
=
None
,
data
=
None
,
**
kwargs
):
def
__init__
(
self
,
instance
=
None
,
data
=
None
,
**
kwargs
):
self
.
instance
=
instance
self
.
instance
=
instance
self
.
_initial_data
=
data
self
.
_initial_data
=
data
...
@@ -65,8 +70,11 @@ class BaseSerializer(Field):
...
@@ -65,8 +70,11 @@ class BaseSerializer(Field):
# We override this method in order to automagically create
# We override this method in order to automagically create
# `ListSerializer` classes instead when `many=True` is set.
# `ListSerializer` classes instead when `many=True` is set.
if
kwargs
.
pop
(
'many'
,
False
):
if
kwargs
.
pop
(
'many'
,
False
):
kwargs
[
'child'
]
=
cls
()
list_kwargs
=
{
'child'
:
cls
(
*
args
,
**
kwargs
)}
return
ListSerializer
(
*
args
,
**
kwargs
)
for
key
in
kwargs
.
keys
():
if
key
in
LIST_SERIALIZER_KWARGS
:
list_kwargs
[
key
]
=
kwargs
[
key
]
return
ListSerializer
(
*
args
,
**
list_kwargs
)
return
super
(
BaseSerializer
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
return
super
(
BaseSerializer
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
...
...
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