mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Merge e652922ebf
into 5882a7a9d5
This commit is contained in:
commit
cbe0926172
|
@ -154,9 +154,11 @@ We now include a simpler `ValidationFailed` exception class in REST framework th
|
||||||
|
|
||||||
The `validate_<field_name>` method hooks that can be attached to serializer classes change their signature slightly and return type. Previously these would take a dictionary of all incoming data, and a key representing the field name, and would return a dictionary including the validated data for that field:
|
The `validate_<field_name>` method hooks that can be attached to serializer classes change their signature slightly and return type. Previously these would take a dictionary of all incoming data, and a key representing the field name, and would return a dictionary including the validated data for that field:
|
||||||
|
|
||||||
|
from rest_framework.exceptions import ValidationFailed
|
||||||
|
|
||||||
def validate_score(self, attrs, source):
|
def validate_score(self, attrs, source):
|
||||||
if attrs[score] % 10 != 0:
|
if attrs[score] % 10 != 0:
|
||||||
raise ValidationError('This field should be a multiple of ten.')
|
raise ValidationFailed('This field should be a multiple of ten.')
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
This is now simplified slightly, and the method hooks simply take the value to be validated, and return it's validated value.
|
This is now simplified slightly, and the method hooks simply take the value to be validated, and return it's validated value.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user