Considering that (http://web2py.com/book/default/chapter/07#Validators)
- a w2p validator acts at form level
- we can get the value of another field on the form through "request.vars"
- in IS_NOT_IN_DB validator, first parameter can be a set of records

a possible answer to your question is

db.dog.owner.requires = IS_IN_DB(db, db.person.id, 'person.name') # 
optional but advised
owner_dogs = db(db.dog.owner==request.vars.owner)
db.dog.name.requires = IS_NOT_IN_DB(owner_dogs, db.dog.name)


Il giorno martedì 13 novembre 2012 15:24:56 UTC+1, dederocks ha scritto:
>
> Say I have the following tables:
>
> db.define_table('person', Field('name', unique=True))
> db.define_table('dog', Field('name'), Field('owner', db.person)
>
> Now on the dog table, I want to add a validator to ensure that all the dogs 
> that belong to one person have a unique name. In other words, if Bill has the 
> dogs Alissa, Muff and Ouahoo, and John has the dogs Muff, Ouahoo and Gisbi 
> it's OK, but not if John has the dogs Muff, Ouahoo and Muff. How can I define 
> a validator to do that?
>
>

-- 



Reply via email to