python - 如何将上下文从向导传递到视图。奥多 13
问题描述
在向导中,我添加了一个字段product_id
和按钮。选择产品并单击按钮时,我想获得stock.quant
产品的树形视图。如何在上下文中传递价值?
class Wizard(models.TransientModel):
_name = 'wizard.wizard'
product_id = fields.Many2one('product.product', string="Product")
@api.model
def my_button(self):
return {
'name': _('Products'),
'view_type': 'tree',
'view_mode': 'list',
'res_model': 'stock.quant',
'context': {},
'type': 'ir.actions.act_window',
'target': 'new',
}
解决方案
self
表示当前记录集。我们可以通过self.product_id
例如:
"context": {"default_product_id": self.product_id.id,
"search_default_product_id": self.product_id.id},
推荐阅读
- javascript - 删除多个数组并更新redux中的状态
- postgresql - PostgreSQL HashAggregate 性能不足
- php - 数据未显示在 jquery DataTable 中
- java - 文件通配符使用 *
- android - Android DialogFlow V2 SDK Java 客户端库 Grpc Google Cloud Platform 从实时音频流中检测意图
- mongodb - MongoDB 关闭并显示代码:12
- feathersjs - 在羽毛钩子中获取内容类型
- neo4j - 当数据库为空时,ANY 函数不返回任何内容
- html - Ng-Show 无法正常工作
- microsoft-graph-api - 检测和获取嵌套组的成员