mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
Merge pull request #92 from mwesterhof/master
Serializer.serialize_model fix of uncaught _SkipField exceptions
This commit is contained in:
commit
4f38e78580
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user