mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 05:54:01 +03:00
OnTheFlySerializer should inherit from the user defined resource
This commit is contained in:
parent
54a02c1fb9
commit
b9f0054ae2
|
@ -146,8 +146,10 @@ class Serializer(object):
|
||||||
# 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)):
|
if isinstance(info, (list, tuple)):
|
||||||
class OnTheFlySerializer(Serializer):
|
# We can only preserve all the (serialization) methods from the resource
|
||||||
fields = info
|
# class if we inherit from the resource, not if we inherit from the
|
||||||
|
# `Serializer` class. Gotta love dynamic languages.
|
||||||
|
OnTheFlySerializer = type('OnTheFlySerializer', (self.__class__,), {'fields': info})
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user