Bruno, I like the second option, but I take a look: def workers(): make_menu('Ventures') venture_name = '' venture_id = '' fields = [] btn_back = None
if request.args(0): if not session.url_back: try: btn_back = make_button_text(" " + T("Ventures"), T("Ventures"), request.wsgi.environ['HTTP_REFERER'], True, "icon leftarrow icon-arrow-left") session.url_back = request.wsgi.environ['HTTP_REFERER'] except: btn_back = make_button_text(" " + T("Ventures"), T("Ventures"), URL("venture", "index"), True, "icon leftarrow icon-arrow-left") else: btn_back = make_button_text(" " + T("Ventures"), T("Ventures"), session.url_back, True, "icon leftarrow icon-arrow-left") venture_id = request.args(0) # Isso é o mesmo que fazer uma Query com Occurrence.venture == request.args(0) e passar a query para a grid ao invés da tabela VentureWorker._common_filter = lambda query: VentureWorker.venture == venture_id venture_row = db(Venture.id == venture_id).select().first() if venture_row: venture_name = ' - ' + venture_row.name fields=[VentureWorker.worker] if request.args(1) == 'new': if venture_row: VentureWorker.venture.default = venture_id else: redirect(URL('venture', 'norms', args=[venture_id])) createargs = {'fields':['worker']} editargs = {'fields':['worker']} viewargs = {'fields':['worker']} return dict(form=SQLFORM.grid(VentureWorker, csv=False, user_signature=True, args=[venture_id], maxtextlength=100, createargs=createargs, editargs = editargs, viewargs = viewargs, fields=fields), subtitle=T('Venture Norms') + venture_name, btn_back=btn_back) I have only one return... How can I use process? Sorry for the questions so newbies, is that this is my first serious project using web2py... Thanks again, man! On Sat, Jan 26, 2013 at 3:35 PM, Bruno Rocha <rochacbr...@gmail.com> wrote: > I can think on two options. > > *1. Unique Key* > > db.define_table("table", > Field("table_a", "reference table_a"), > Field("table_b", "reference table_b"), > Field("unikey", unique=True, notnull=True, compute=lambda row: > "%(table_a)s-%(table_b)s" % row) > ) > > > *2. Form validator* > > def check_unique(form): > if db((db.table.table_a == form.vars.table_a) & (db.table.table_b == > form.vars.table_b)).count(): > form.errors.table_a = "You cannot insert or edit a duplicate > combination" > > form = SQLFORM(db.table).process(onvalidation=check_unique) > > Mybe it can be implemented as a Field Validator, have to try. > > -- > > > > --