diff options
| author | Tom Christie | 2013-01-26 21:37:43 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-01-26 21:37:43 +0000 |
| commit | b5d8f50f9dcace3ad3c708ed518f23ff260f6bea (patch) | |
| tree | 7a0fb931ad5841b863359719075dd55f8370b3a1 /rest_framework/serializers.py | |
| parent | 4eb5861f3676781493af29f8e9fd87ec22e591aa (diff) | |
| parent | a75db4cfb8ed756c451bfda7ea0c73a73859216f (diff) | |
| download | django-rest-framework-b5d8f50f9dcace3ad3c708ed518f23ff260f6bea.tar.bz2 | |
Merge branch 'master' into many-fields
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 27458f96..6ecc7b45 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -2,6 +2,7 @@ import copy import datetime import types from decimal import Decimal +from django.core.paginator import Page from django.db import models from django.forms import widgets from django.utils.datastructures import SortedDict @@ -227,6 +228,8 @@ class BaseSerializer(Field): Run `validate_<fieldname>()` and `validate()` methods on the serializer """ for field_name, field in self.fields.items(): + if field_name in self._errors: + continue try: validate_method = getattr(self, 'validate_%s' % field_name, None) if validate_method: @@ -271,7 +274,11 @@ class BaseSerializer(Field): """ Serialize objects -> primitives. """ - if hasattr(obj, '__iter__'): + # Note: At the moment we have an ugly hack to determine if we should + # walk over iterables. At some point, serializers will require an + # explicit `many=True` in order to iterate over a set, and this hack + # will disappear. + if hasattr(obj, '__iter__') and not isinstance(obj, Page): return [self.convert_object(item) for item in obj] return self.convert_object(obj) @@ -298,6 +305,9 @@ class BaseSerializer(Field): Override default so that we can apply ModelSerializer as a nested field to relationships. """ + if self.source == '*': + return self.to_native(obj) + try: if self.source: for component in self.source.split('.'): |
