diff options
Diffstat (limited to 'djangorestframework/serializer.py')
| -rw-r--r-- | djangorestframework/serializer.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index 82aeb53f..22efa5ed 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -177,7 +177,7 @@ class Serializer(object): Keys serialize to their string value, unless they exist in the `rename` dict. """ - return getattr(self.rename, smart_str(key), smart_str(key)) + return self.rename.get(smart_str(key), smart_str(key)) def serialize_val(self, key, obj): @@ -229,16 +229,16 @@ class Serializer(object): # serialize each required field for fname in fields: if hasattr(self, smart_str(fname)): - # check for a method 'fname' on self first + # check first for a method 'fname' on self first meth = getattr(self, fname) if inspect.ismethod(meth) and len(inspect.getargspec(meth)[0]) == 2: obj = meth(instance) + elif hasattr(instance, '__contains__') and fname in instance: + # check for a key 'fname' on the instance + obj = instance[fname] elif hasattr(instance, smart_str(fname)): - # now check for an attribute 'fname' on the instance + # finally check for an attribute 'fname' on the instance obj = getattr(instance, fname) - elif fname in instance: - # finally check for a key 'fname' on the instance - obj = instance[fname] else: continue |
