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
e9fda70b
Commit
e9fda70b
authored
Jan 15, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nicer write_only fields implementation. Closes #1355
parent
9d6129a9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
9 deletions
+3
-9
rest_framework/fields.py
+1
-5
rest_framework/serializers.py
+2
-4
No files found.
rest_framework/fields.py
View file @
e9fda70b
...
@@ -114,10 +114,6 @@ def strip_multiple_choice_msg(help_text):
...
@@ -114,10 +114,6 @@ def strip_multiple_choice_msg(help_text):
return
help_text
.
replace
(
multiple_choice_msg
,
''
)
return
help_text
.
replace
(
multiple_choice_msg
,
''
)
class
IgnoreFieldException
(
Exception
):
pass
class
Field
(
object
):
class
Field
(
object
):
read_only
=
True
read_only
=
True
creation_counter
=
0
creation_counter
=
0
...
@@ -329,7 +325,7 @@ class WritableField(Field):
...
@@ -329,7 +325,7 @@ class WritableField(Field):
def
field_to_native
(
self
,
obj
,
field_name
):
def
field_to_native
(
self
,
obj
,
field_name
):
if
self
.
write_only
:
if
self
.
write_only
:
r
aise
IgnoreFieldException
()
r
eturn
None
return
super
(
WritableField
,
self
)
.
field_to_native
(
obj
,
field_name
)
return
super
(
WritableField
,
self
)
.
field_to_native
(
obj
,
field_name
)
def
field_from_native
(
self
,
data
,
files
,
field_name
,
into
):
def
field_from_native
(
self
,
data
,
files
,
field_name
,
into
):
...
...
rest_framework/serializers.py
View file @
e9fda70b
...
@@ -346,13 +346,11 @@ class BaseSerializer(WritableField):
...
@@ -346,13 +346,11 @@ class BaseSerializer(WritableField):
continue
continue
field
.
initialize
(
parent
=
self
,
field_name
=
field_name
)
field
.
initialize
(
parent
=
self
,
field_name
=
field_name
)
key
=
self
.
get_field_key
(
field_name
)
key
=
self
.
get_field_key
(
field_name
)
try
:
value
=
field
.
field_to_native
(
obj
,
field_name
)
value
=
field
.
field_to_native
(
obj
,
field_name
)
except
IgnoreFieldException
:
continue
method
=
getattr
(
self
,
'transform_
%
s'
%
field_name
,
None
)
method
=
getattr
(
self
,
'transform_
%
s'
%
field_name
,
None
)
if
callable
(
method
):
if
callable
(
method
):
value
=
method
(
obj
,
value
)
value
=
method
(
obj
,
value
)
if
not
getattr
(
field
,
'write_only'
,
False
):
ret
[
key
]
=
value
ret
[
key
]
=
value
ret
.
fields
[
key
]
=
self
.
augment_field
(
field
,
field_name
,
key
,
value
)
ret
.
fields
[
key
]
=
self
.
augment_field
(
field
,
field_name
,
key
,
value
)
...
@@ -389,7 +387,7 @@ class BaseSerializer(WritableField):
...
@@ -389,7 +387,7 @@ class BaseSerializer(WritableField):
across relationships.
across relationships.
"""
"""
if
self
.
write_only
:
if
self
.
write_only
:
r
aise
IgnoreFieldException
()
r
eturn
None
if
self
.
source
==
'*'
:
if
self
.
source
==
'*'
:
return
self
.
to_native
(
obj
)
return
self
.
to_native
(
obj
)
...
...
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