diff options
| author | Tom Christie | 2012-01-11 06:53:32 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-01-11 06:53:32 -0800 |
| commit | e8ddbf435cc6ed66e2a5595d2d6a0696377b825a (patch) | |
| tree | a32df3af3e48fb9612844ab6ab36bb90a61a9408 /djangorestframework/serializer.py | |
| parent | 840845e9eff35299ffc524f8aea806c9a8a4b54c (diff) | |
| parent | 792bc4d60814af026f926a4c92a9d4a8e3124341 (diff) | |
| download | django-rest-framework-e8ddbf435cc6ed66e2a5595d2d6a0696377b825a.tar.bz2 | |
Merge pull request #121 from sebpiq/issue-73
Fixes #73.
Thanks @sebpiq, @ekohl!
Diffstat (limited to 'djangorestframework/serializer.py')
| -rw-r--r-- | djangorestframework/serializer.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index 429adea2..43d32b29 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -230,13 +230,14 @@ class Serializer(object): # serialize each required field for fname in fields: try: - if hasattr(self, smart_str(fname)): - # 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) + # we first check for a method 'fname' on self, + # 'fname's signature must be 'def fname(self, instance)' + meth = getattr(self, fname, None) + 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 + # then check for a key 'fname' on the instance obj = instance[fname] elif hasattr(instance, smart_str(fname)): # finally check for an attribute 'fname' on the instance |
