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
0240df1a
Commit
0240df1a
authored
Feb 06, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor internal API cleanpu
parent
670723f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
rest_framework/serializers.py
+8
-9
No files found.
rest_framework/serializers.py
View file @
0240df1a
...
...
@@ -855,8 +855,9 @@ class ModelSerializer(Serializer):
)
# Include any kwargs defined in `Meta.extra_kwargs`
field_kwargs
=
self
.
build_field_kwargs
(
field_kwargs
,
extra_kwargs
,
field_name
extra_field_kwargs
=
extra_kwargs
.
get
(
field_name
,
{})
field_kwargs
=
self
.
include_extra_kwargs
(
field_kwargs
,
extra_field_kwargs
)
# Create the serializer field.
...
...
@@ -1064,14 +1065,12 @@ class ModelSerializer(Serializer):
(
field_name
,
model_class
.
__name__
)
)
def
build_field_kwargs
(
self
,
kwargs
,
extra_kwargs
,
field_name
):
def
include_extra_kwargs
(
self
,
kwargs
,
extra_kwargs
):
"""
Include an 'extra_kwargs' that have been included for this field,
Include an
y
'extra_kwargs' that have been included for this field,
possibly removing any incompatible existing keyword arguments.
"""
extras
=
extra_kwargs
.
get
(
field_name
,
{})
if
extras
.
get
(
'read_only'
,
False
):
if
extra_kwargs
.
get
(
'read_only'
,
False
):
for
attr
in
[
'required'
,
'default'
,
'allow_blank'
,
'allow_null'
,
'min_length'
,
'max_length'
,
'min_value'
,
'max_value'
,
...
...
@@ -1079,10 +1078,10 @@ class ModelSerializer(Serializer):
]:
kwargs
.
pop
(
attr
,
None
)
if
extras
.
get
(
'default'
)
and
kwargs
.
get
(
'required'
)
is
False
:
if
extra
_kwarg
s
.
get
(
'default'
)
and
kwargs
.
get
(
'required'
)
is
False
:
kwargs
.
pop
(
'required'
)
kwargs
.
update
(
extras
)
kwargs
.
update
(
extra
_kwarg
s
)
return
kwargs
...
...
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