odoo acquire all the attributes of the data model

  • A law
    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')}
  • Act II
    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')}

Guess you like

Origin www.cnblogs.com/edhg/p/11453545.html