This commit is contained in:
Tom Christie 2014-10-10 14:32:02 +01:00
parent d9a199ca0d
commit d8a8987ab1
2 changed files with 7 additions and 1 deletions

View File

@ -144,6 +144,12 @@ The corresponding code would now look like this:
logging.info('Creating ticket "%s"' % name) logging.info('Creating ticket "%s"' % name)
serializer.save(user=request.user) # Include the user when saving. serializer.save(user=request.user) # Include the user when saving.
#### Use `rest_framework.exceptions.ValidationFailed`.
Django's `ValidationError` class is intended for use with HTML forms and it's API makes its use slightly awkward with nested validation errors as can occur in serializers.
We now include a simpler `ValidationFailed` exception class in REST framework that you should use when raising validation failures.
#### Change to `validate_<field_name>`. #### Change to `validate_<field_name>`.
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:

View File

@ -555,7 +555,7 @@ class ModelSerializer(Serializer):
depth = getattr(self.Meta, 'depth', 0) depth = getattr(self.Meta, 'depth', 0)
extra_kwargs = getattr(self.Meta, 'extra_kwargs', {}) extra_kwargs = getattr(self.Meta, 'extra_kwargs', {})
assert not fields and exclude, "Cannot set both 'fields' and 'exclude'." assert not (fields and exclude), "Cannot set both 'fields' and 'exclude'."
extra_kwargs = self._include_additional_options(extra_kwargs) extra_kwargs = self._include_additional_options(extra_kwargs)