zoukankan      html  css  js  c++  java
  • Odoo 8.0 new API 之Environment

    """ An environment wraps data for ORM records:
    
             - :attr:`cr`, the current database cursor;
             - :attr:`uid`, the current user id;
              - :attr:`context`, the current context dictionary.
     
            It also provides access to the registry, a cache for records, and a data
            structure to manage recomputations.
         """

    Environment类提供了对ORM对象的封装,同时提供了对注册类的访问,记录集的缓存,以及管理重计算的数据结构.

    对于继承了Model的类来说可以直接通过self.env对Environment进行操作.

    属性列表:

    1.user:返回当前用户 

    self.env.user

    2.lang:返回当前语言代码

    self.env.lang

    3.in_draft:返回是否处于草稿模式

    self.env.in_draft

    4.in_onchange:返回是否处于'onchange'草稿模式

    self.env.in_onchange

    另外还有cr,registery,cache,prefetch,computed,dirty,todo,mode,all等属性

    应用说明:

    1.利用env[model]获取类对象:

    self.env['ir.model'].search([('state', '!=', 'manual')])

    2.利用cr执行sql语句:

    self.env.cr.execute(query, (value,))
  • 相关阅读:
    简介&目录
    Lucas 定理
    扩展欧几里得算法(exgcd)
    【做题记录】CF23B Party
    【做题记录】CF1375D Replace by MEX
    【做题记录】CF194B Square
    SPFA
    dijkstra
    CSP-J&S 2020 游记
    中国剩余定理(CRT)
  • 原文地址:https://www.cnblogs.com/dancesir/p/6931895.html
Copyright © 2011-2022 走看看