def __init__(self, *args, **kwargs): super(Model, self).__init__(*args, **kwargs) for i, j in self._data.items(): if isinstance(j, list): for x in j: set_parent(x, self) else: set_parent(j, self)
def test_set_parent(self): item = mock.MagicMock() parent = mock.MagicMock() item.__parent__ = 'not_none_value' set_parent(item=item, parent=parent) self.assertEqual(item.__parent__, 'not_none_value') item.__parent__ = None set_parent(item=item, parent=parent) self.assertEqual(item.__parent__, parent)
def convert(self, raw_data, **kw): """ Converts the raw data into richer Python constructs according to the fields on the model """ value = convert(self.__class__, raw_data, **kw) for i, j in value.items(): if isinstance(j, list): for x in j: set_parent(x, self) else: set_parent(j, self) return value