@classmethod<EOL><INDENT>def obj_to_dict(cls, obj):<DEDENT>
data = {}<EOL>for field_name in cls.get_fields():<EOL><INDENT>try:<EOL><INDENT>value = getattr(obj, field_name)<EOL><DEDENT>except AttributeError:<EOL><INDENT>continue<EOL><DEDENT>if callable(value):<EOL><INDENT>value = value()<EOL><DEDENT>data[field_name] = value<EOL><DEDENT>return data<EOL>
Takes a model object and converts it into a dictionary suitable for
passing to the constructor's data attribute.