I've created a simple code.
In my db_task.py I have the following lines, among others:
from applications.myapp.modules.mywidgets import *
db.main.product.requires=IS_IN_DB(db,
db.product.id,
db.product.name,
orderby=~
db.product.name)
db.main.product.widget = options_with_add_link.widget
And in my module mywidgets.py I have the class:
class options_with_add_link(SQLFORM):
@staticmethod
def widget(field,value,**attr):
select = OptionsWidget.widget(field,value,**attr)
id = "%(tablename)s_%(fieldname)s" %
{"tablename":field._tablename,"fieldname":
field.name}
script_add_button = SCRIPT(
"""$(document).ready(function() {
$("#%(id)s").after(
\"<a target='_blank' href=\'%(url)s\'>%(text)s</a>\"
);
}
)""" % {"id" : id,"url":URL
(a="myapp",c=
field.name,f="create"),"text":"Add"}
)
return DIV(select, script_add_button)
Notice above, in the line where I create the "add" link, that I call
the "URL" method by passing hard coded values. I don't want it.