Reputation: 845
is it possible to use a field from the model as attribute inside an html tag.
Specifically in a form view I would like to create a link to an external issue tracker from the issue number taken from my model. I would like to display the issue number as link text with the full URL as external target.
Like that:
<a href="www.example.com" target="_blank"><field name="issue_nr" nolabel="1"/></a>
This is working nicely so far as I get a link to the URL displayed with the issue number as label and in edit mode I get a text field where I can change the issue number itself.
My problem is that I don't know how to set the href attribute dynamically. The idea would be to get the link build by a dynamic field. I tried this and it is working well, but I don't know how to get the content of that dynamic field inside the href attribute of the anchor.
Any ideas? I don't necessarily need a field for href. If it's possible to do this with python code, that would be fine too.
Thanks and regards,
Peter
Upvotes: 0
Views: 1458
Reputation: 614
I suggest adding a functional field in your model in python:
def _generate_href(self, cr, uid, ids, field, arg, context=None):
res = {}
for id in ids:
issue = self.browse(cr, uid, id)
res[id] = "http://example.com/" + str(issue.issue_nr)
return res
_columns = {
#...
href_link: fields.function(_generate_href, type="char", size=128, string='Web address')
#...
}
And then in your view you can do this:
<field name="href_link" nolabel="1" widget="url" readonly="1"/>
Upvotes: -1