Allow callables in dotted notation like Field(source='foo.bar')

This commit is contained in:
Tom Christie 2012-10-18 22:02:44 +01:00
parent 0c65d9babe
commit d1746e2f3c

View File

@ -70,6 +70,8 @@ class Field(object):
value = obj value = obj
for component in self.source.split('.'): for component in self.source.split('.'):
value = getattr(value, component) value = getattr(value, component)
if is_simple_callable(value):
value = value()
else: else:
value = getattr(obj, field_name) value = getattr(obj, field_name)
return self.to_native(value) return self.to_native(value)