Don't ever return the normal serializer again.

This commit is contained in:
Alen Mujezinovic 2012-08-13 15:58:23 +01:00
parent e3d7c36105
commit 2f9775c12d

View File

@ -135,10 +135,12 @@ class Serializer(object):
# If an element in `fields` is a 2-tuple of (str, tuple) # If an element in `fields` is a 2-tuple of (str, tuple)
# then the second element of the tuple is the fields to # then the second element of the tuple is the fields to
# set on the related serializer # set on the related serializer
if isinstance(info, (list, tuple)):
class OnTheFlySerializer(self.__class__): class OnTheFlySerializer(self.__class__):
fields = info fields = info
parent = getattr(self, 'parent') or self parent = getattr(self, 'parent') or self
if isinstance(info, (list, tuple)):
return OnTheFlySerializer return OnTheFlySerializer
# If an element in `fields` is a 2-tuple of (str, Serializer) # If an element in `fields` is a 2-tuple of (str, Serializer)
@ -156,8 +158,9 @@ class Serializer(object):
elif isinstance(info, str) and info in _serializers: elif isinstance(info, str) and info in _serializers:
return _serializers[info] return _serializers[info]
# Otherwise use `related_serializer` or fall back to `Serializer` # Otherwise use `related_serializer` or fall back to
return getattr(self, 'related_serializer') or Serializer # `OnTheFlySerializer` preserve custom serialization methods.
return getattr(self, 'related_serializer') or OnTheFlySerializer
def serialize_key(self, key): def serialize_key(self, key):
""" """