mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 02:24:03 +03:00
Don't ever return the normal serializer again.
This commit is contained in:
parent
e3d7c36105
commit
2f9775c12d
|
@ -135,10 +135,12 @@ class Serializer(object):
|
|||
# If an element in `fields` is a 2-tuple of (str, tuple)
|
||||
# then the second element of the tuple is the fields to
|
||||
# set on the related serializer
|
||||
if isinstance(info, (list, tuple)):
|
||||
|
||||
class OnTheFlySerializer(self.__class__):
|
||||
fields = info
|
||||
parent = getattr(self, 'parent') or self
|
||||
|
||||
if isinstance(info, (list, tuple)):
|
||||
return OnTheFlySerializer
|
||||
|
||||
# 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:
|
||||
return _serializers[info]
|
||||
|
||||
# Otherwise use `related_serializer` or fall back to `Serializer`
|
||||
return getattr(self, 'related_serializer') or Serializer
|
||||
# Otherwise use `related_serializer` or fall back to
|
||||
# `OnTheFlySerializer` preserve custom serialization methods.
|
||||
return getattr(self, 'related_serializer') or OnTheFlySerializer
|
||||
|
||||
def serialize_key(self, key):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user