From b9f0054ae2efaad133261822ac99151975db9286 Mon Sep 17 00:00:00 2001 From: Alen Mujezinovic Date: Tue, 21 Feb 2012 12:41:24 +0000 Subject: [PATCH] OnTheFlySerializer should inherit from the user defined resource --- djangorestframework/serializer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index 71c0d93ae..18e55b3ef 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -146,8 +146,10 @@ class Serializer(object): # then the second element of the tuple is the fields to # set on the related serializer if isinstance(info, (list, tuple)): - class OnTheFlySerializer(Serializer): - fields = info + # We can only preserve all the (serialization) methods from the resource + # 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 # If an element in `fields` is a 2-tuple of (str, Serializer)