summaryrefslogtreecommitdiff
path: root/django/core/serializers/python.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-04-13 12:35:49 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-04-13 12:35:49 +0000
commitcb43898d49ac60bf84a2eb83b331072e7651af5e (patch)
tree1dfed754b16d60b3791feaca9d420010864b72ba /django/core/serializers/python.py
parentfd3ee7d7867dd13a336b90873ccb8df6302f2c05 (diff)
Fixed #9522 -- Modified handling of values in base serializer so that field subclasses can define their own value_to_string() method for serialization. Thanks to Alex Koshelev for the report and initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10554 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/serializers/python.py')
-rw-r--r--django/core/serializers/python.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py
index 0eeb485797..b672e4efc3 100644
--- a/django/core/serializers/python.py
+++ b/django/core/serializers/python.py
@@ -7,15 +7,15 @@ other serializers.
from django.conf import settings
from django.core.serializers import base
from django.db import models
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_unicode, is_protected_type
class Serializer(base.Serializer):
"""
Serializes a QuerySet to basic Python objects.
"""
-
+
internal_use_only = True
-
+
def start_serialization(self):
self._current = None
self.objects = []
@@ -35,7 +35,14 @@ class Serializer(base.Serializer):
self._current = None
def handle_field(self, obj, field):
- self._current[field.name] = smart_unicode(getattr(obj, field.name), strings_only=True)
+ value = field._get_val_from_obj(obj)
+ # Protected types (i.e., primitives like None, numbers, dates,
+ # and Decimals) are passed through as is. All other values are
+ # converted to string first.
+ if is_protected_type(value):
+ self._current[field.name] = value
+ else:
+ self._current[field.name] = field.value_to_string(obj)
def handle_fk_field(self, obj, field):
related = getattr(obj, field.name)