Thanks for the fast response. This works perfectly. You said using like is way less efficient, is there a way to use IS_NOT_IN_DB that would achieve the same goal?
On Oct 16, 3:45 pm, mdipierro <[email protected]> wrote: > Two things... > 1) > > db.firm.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, > 'firm.name')] > > and > > db.firm.name.requires = IS_NOT_IN_DB(db, 'firm.name') > > are equivalent. Is not in db, does not accept empty anyway. > Back to your question. > > You can make your own validator: > > class IS_NOT_IN_DB_ANYCASE: > def __init__(self,db, field, error_message='oops') > self.db=db > self.tablename,self.fieldname=field.split('.') > self.error_message=error_message > def __call__(self,value): > if self.db(self.db[self.tablename] > [self.fieldname].like(value)).count(): > return (value,self.error_message) > return (value,None) > > db.firm.name.requires = IS_NOT_IN_DB_ANYCASE(db, 'firm.name') > > but using like is way less efficient that not IS_NOT_IN_DB. > > On Oct 16, 5:18 pm, oneroler <[email protected]> wrote: > > > > > I just started working with web2py and have what is probably a simple > > question on database validation. Below is what I have in db.py. > > Currently this will allow duplicate names that are in different cases > > (e.g. Firm 1 and firm 1). I want to make it so that it won't allow > > this but stores the name in the database the way the person enters it, > > so I don't want to convert everything to upper or lowercase and store > > it that way. Thanks in advance for any help. > > > db.define_table('firm', > > Field('name', unique=True)) > > > db.firm.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'firm.name')]

