diff options
| author | Marko Tibold | 2011-12-13 04:06:40 -0800 |
|---|---|---|
| committer | Marko Tibold | 2011-12-13 04:06:40 -0800 |
| commit | 4f38e78580ff0aa1f8b89b92703b5b97c24ec003 (patch) | |
| tree | 15ae949f2c6b4459f838486ce8323bdc0c019c6b /djangorestframework/serializer.py | |
| parent | 8cd7ab14228cdfc308a1e4796016b5c00bdf8d8e (diff) | |
| parent | 2be350293bdd7a3e64e8f43a4b8424e277b7dc66 (diff) | |
| download | django-rest-framework-4f38e78580ff0aa1f8b89b92703b5b97c24ec003.tar.bz2 | |
Merge pull request #92 from mwesterhof/master
Serializer.serialize_model fix of uncaught _SkipField exceptions
Diffstat (limited to 'djangorestframework/serializer.py')
| -rw-r--r-- | djangorestframework/serializer.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index 55b84df1..bb77ef7d 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -229,21 +229,21 @@ class Serializer(object): # serialize each required field for fname in fields: - 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) - 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)): - # finally check for an attribute 'fname' on the instance - obj = getattr(instance, fname) - else: - continue - 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) + 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)): + # finally check for an attribute 'fname' on the instance + obj = getattr(instance, fname) + else: + continue + key = self.serialize_key(fname) val = self.serialize_val(fname, obj) data[key] = val |
