It is not too simple. Given:

db.define_table('table1', Field('name'))
db.define_table('table2',Field('name'),Field(table1','reference table1'))

define:

def require_unique(form):
      if db.table2(name=form.vars.name,table1=form.vars.table1): 
form.errors.name="Must be unique!"

then when processing forms apply the above check:

form = SQLFORM(db.table2)
form.process(onvalidation=require_unique)

On Wednesday, 25 June 2014 10:17:17 UTC-5, KRG KCIHTRAK wrote:
>
> I have two tables like below.
> Table1 (Field(name), unique = True)
> Table2 (Field(table1_name, 'reference Table1',
>            Field(name))
>
> I want to make the Table2's name field as unique based on the value in 
> table1_name.
>
> how can I do it with web2py?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to