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
f72928ea
Commit
f72928ea
authored
Dec 19, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build_field, build_final_kwargs
parent
94883ae7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
rest_framework/serializers.py
+25
-8
No files found.
rest_framework/serializers.py
View file @
f72928ea
...
...
@@ -908,7 +908,22 @@ class ModelSerializer(Serializer):
ret
[
field_name
]
=
declared_fields
[
field_name
]
continue
elif
field_name
in
info
.
fields_and_pk
:
# Determine the serializer field class and keyword arguments.
field_cls
,
kwargs
=
self
.
build_field
(
field_name
,
info
,
model
,
depth
)
# Populate any kwargs defined in `Meta.extra_kwargs`
kwargs
=
self
.
build_final_kwargs
(
kwargs
,
extra_kwargs
,
field_name
)
# Create the serializer field.
ret
[
field_name
]
=
field_cls
(
**
kwargs
)
# Add in any hidden fields.
ret
.
update
(
hidden_fields
)
return
ret
def
build_field
(
self
,
field_name
,
info
,
model
,
depth
):
if
field_name
in
info
.
fields_and_pk
:
# Create regular model fields.
model_field
=
info
.
fields_and_pk
[
field_name
]
field_cls
=
self
.
_field_mapping
[
model_field
]
...
...
@@ -955,8 +970,15 @@ class ModelSerializer(Serializer):
(
field_name
,
model
.
__class__
.
__name__
)
)
# Populate any kwargs defined in `Meta.extra_kwargs`
return
field_cls
,
kwargs
def
build_final_kwargs
(
self
,
kwargs
,
extra_kwargs
,
field_name
):
"""
Include an '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
):
for
attr
in
[
'required'
,
'default'
,
'allow_blank'
,
'allow_null'
,
...
...
@@ -970,12 +992,7 @@ class ModelSerializer(Serializer):
kwargs
.
update
(
extras
)
# Create the serializer field.
ret
[
field_name
]
=
field_cls
(
**
kwargs
)
ret
.
update
(
hidden_fields
)
return
ret
return
kwargs
def
_get_model_fields
(
self
,
field_names
,
declared_fields
,
extra_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