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
2250ab64
Commit
2250ab64
authored
Jan 21, 2013
by
Stephan Groß
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possible solution for field validation error
parent
dc1c57d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
rest_framework/serializers.py
+8
-7
No files found.
rest_framework/serializers.py
View file @
2250ab64
...
...
@@ -227,13 +227,14 @@ class BaseSerializer(Field):
Run `validate_<fieldname>()` and `validate()` methods on the serializer
"""
for
field_name
,
field
in
self
.
fields
.
items
():
try
:
validate_method
=
getattr
(
self
,
'validate_
%
s'
%
field_name
,
None
)
if
validate_method
:
source
=
field
.
source
or
field_name
attrs
=
validate_method
(
attrs
,
source
)
except
ValidationError
as
err
:
self
.
_errors
[
field_name
]
=
self
.
_errors
.
get
(
field_name
,
[])
+
list
(
err
.
messages
)
if
field_name
not
in
self
.
_errors
:
try
:
validate_method
=
getattr
(
self
,
'validate_
%
s'
%
field_name
,
None
)
if
validate_method
:
source
=
field
.
source
or
field_name
attrs
=
validate_method
(
attrs
,
source
)
except
ValidationError
as
err
:
self
.
_errors
[
field_name
]
=
self
.
_errors
.
get
(
field_name
,
[])
+
list
(
err
.
messages
)
# If there are already errors, we don't run .validate() because
# field-validation failed and thus `attrs` may not be complete.
...
...
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