Odoo/Python 如何重定向到网站
Odoo/Python how to redirect to a website
在我的表单视图中,每条记录都应该有一个带有重定向到特定网站的图标。例如:
记录 1 | www.test.com/a
记录2 | www.test.com/b
如何创建这样的点击重定向?
我尝试了一个按钮 - 但我不知道如何在操作中重定向:
<form string="MyForm">
<sheet>
<group>
<page string="MyPage">
<field name="MyRecords" widget="one2many_list">
<tree string="Records">
<field name="identifier"/>
<field name="recordname"/>
<button type="object" name="open_record_action" icon="fa-external-link" />
</tree>
</field>
</page>
<page>
...
</page>
</group>
<group>
...
</group>
</sheet>
模型中:
@api.multi
def open_record_action(self, context):
????
另一种可能的解决方案是将 link 存储在模型的字段中并以这种方式在视图中实现它:
<field name="url" widget="url"/>
但是使用此解决方案会显示 link。但我只想看到图标。
有什么解决办法吗?
您可以使用 "ir.actions.act_url":
return {
'type': 'ir.actions.act_url',
'url': '/forum/%s/question/%s' % (self.forum_id.id, self.id),
'target': 'self',
'res_id': self.id,
}
例如检查website_forum/models/forum.py
。
在我的表单视图中,每条记录都应该有一个带有重定向到特定网站的图标。例如:
记录 1 | www.test.com/a
记录2 | www.test.com/b
如何创建这样的点击重定向?
我尝试了一个按钮 - 但我不知道如何在操作中重定向:
<form string="MyForm">
<sheet>
<group>
<page string="MyPage">
<field name="MyRecords" widget="one2many_list">
<tree string="Records">
<field name="identifier"/>
<field name="recordname"/>
<button type="object" name="open_record_action" icon="fa-external-link" />
</tree>
</field>
</page>
<page>
...
</page>
</group>
<group>
...
</group>
</sheet>
模型中:
@api.multi
def open_record_action(self, context):
????
另一种可能的解决方案是将 link 存储在模型的字段中并以这种方式在视图中实现它:
<field name="url" widget="url"/>
但是使用此解决方案会显示 link。但我只想看到图标。
有什么解决办法吗?
您可以使用 "ir.actions.act_url":
return {
'type': 'ir.actions.act_url',
'url': '/forum/%s/question/%s' % (self.forum_id.id, self.id),
'target': 'self',
'res_id': self.id,
}
例如检查website_forum/models/forum.py
。