我们可以在 odoo 中创建一个模型,这样它就不会反射(reflect)在数据库级别吗?
例如:
class SalaOrder(model.models):
_name='sale.order'
我不想在数据库中创建“sale_order”表。
最佳答案
根据models.py
(odoo/odoo/models.py)上的注释,您可以将_auto
设置为False
。
class SalaOrder(model.models):
_name = 'sale.order'
_auto = False
评论说
_auto = False # don't create any database backend
以下是有关 Odoo 模型的更多详细信息(来自同一代码):
Odoo models are created by inheriting:
:class:
Model
for regular database-persisted models:class:
TransientModel
for temporary data, stored in the database but automatically vacuumed every so often:class:
AbstractModel
for abstract super classes meant to be shared by multiple inheriting modelsThe system automatically instantiates every model once per database. Those instances represent the available models on each database, and depend on which modules are installed on that database. The actual class of each instance is built from the Python classes that create and inherit from the corresponding model.
Every model instance is a "recordset", i.e., an ordered collection of records of the model. Recordsets are returned by methods like :meth:
~.browse
, :meth:~.search
, or field accesses. Records have no explicit representation: a record is represented as a recordset of one record.To create a class that should not be instantiated, the _register class attribute may be set to False.
关于python - 在 View 级别创建 odoo 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47886193/