aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorJamie Matthews2012-10-24 11:39:17 +0100
committerJamie Matthews2012-10-24 11:39:17 +0100
commitac2d39892d6b3fbbe5cd53b9ef83367249ba4880 (patch)
tree413fedc79aeedb06722b416fd74af38d767f9c9e /rest_framework/serializers.py
parent388a807f64f60d84556288e2ade4f0fe57a8e66b (diff)
downloaddjango-rest-framework-ac2d39892d6b3fbbe5cd53b9ef83367249ba4880.tar.bz2
Add cross-field validate method
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index 802ca55f..15fe26ee 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -225,6 +225,18 @@ class BaseSerializer(Field):
return data
+ def clean_all(self, attrs):
+ """
+ Run the `validate` method on the serializer, if it exists
+ """
+ try:
+ validate_method = getattr(self, 'validate', None)
+ if validate_method:
+ attrs = validate_method(attrs)
+ except ValidationError as err:
+ self._errors['non_field_errors'] = err.messages
+ return attrs
+
def restore_object(self, attrs, instance=None):
"""
Deserialize a dictionary of attributes into an object instance.
@@ -259,6 +271,7 @@ class BaseSerializer(Field):
if data is not None:
attrs = self.restore_fields(data)
attrs = self.clean_fields(attrs)
+ attrs = self.clean_all(attrs)
else:
self._errors['non_field_errors'] = 'No input provided'