odoo 获取model全部属性的数据

  • 法一
    def get_dict(obj):
        """
        将类中数据以dict形式返回
        :return: dict数据
        """
        obj_dir = obj.__dir__()
        return {i: obj.__getattribute__(i) for i in obj_dir if
                obj_dir.index('<lambda>') < obj_dir.index(i) < obj_dir.index('id')}
  • 法二
    def get_dict(obj):
        """
        将类中数据以dict形式返回
        :return: dict数据
        """
        return {i: obj.__getattribute__(i) for i in obj.__dir__() if
                obj.__dir__().index('<lambda>') < obj.__dir__().index(i) < obj.__dir__().index('id')}

猜你喜欢

转载自www.cnblogs.com/edhg/p/11453545.html