fix for unhandled _SkipField exception in Serializer.serialize_model

This commit is contained in:
Marco Westerhof 2011-12-13 11:14:23 +01:00
parent 8cd7ab1422
commit 2be350293b

View File

@ -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