for now use this. This is a case I never should about before. class MY_ODD_VALIDATOR(IS_IN_DB): def __init__(self,*a,**b): IS_IN_DB.__init__(self,*a,**b) def __call__(self,value): e=IS_IN_DB.__call__(self,value) if e[1]: return e e=IS_NOT_IN_DB(db (db.u.unit_id==request.vars.unit_id),'u.zd_id')(value) return e
db.u.zd_id.requires=MY_ODD_VALIDATOR(db,'zonedef.id','%(nom)s') On Jan 6, 11:40 am, tknack <tknac...@gmail.com> wrote: > Hi Massimo, > > Yes, it works ! But when I try to use IS_NOT_IN_DB with IS_IN_DB, I > can't obtain a drop down list, even if I change the order of the > lines. Here's my code : > > db.define_table('zonedef', > SQLField('nom')) > > db.zonedef.nom.requires=[IS_NOT_EMPTY(error_message='can't be > empty!'),IS_NOT_IN_DB(db,'zonedef.nom')] > > db.zonedef.represent=lambda zonedef: > A(zonedef.nom,_href=t2.action('update',zonedef.id)) > > db.define_table('u_name', > SQLField('nom'), > SQLField('description',length=128)) > > db.define_table('u', > SQLField('unit_id',db.u_name), > SQLField('zd_id',db.zonedef), > SQLField('nb_u','double')) > > db.u.zd_id.requires=IS_IN_DB(db,'zonedef.id','%(nom)s') > db.u.unit_id.requires=IS_IN_DB(db,'u_name.id','%(nom)s : (description) > s') > > db.u.zd_id.requires=IS_NOT_IN_DB(db > (db.u.unit_id==request.vars.unit_id),'u.zd_id') > > Can you help me to fix it, Massimo ? > > On 12 déc 2008, 23:24, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > No. validators are associated to one field in the sense that only one > > field will report the error. > > > db.define_table('t',SQLField('f1'),SQLField('f'2')) > > db.t.f2.requires=IS_NOT_IN_DB(db(db.t.f1==request.vars.f1),'t.f2') > > OR > > db.t.f1.requires=IS_NOT_IN_DB(db(db.t.f2==request.vars.f2),'t.f1') > > > are equivalent and do exactly what you ask. except that the former > > associates the error with the f1 value and the second to the f2 value. > > They both generate the query > > > db((db.t.f1==request.vars.f1)&(db.t.f2==request.vars.f2)).count() > > > Massimo > > > On Dec 12, 4:01 pm, DenesL <denes1...@yahoo.ca> wrote: > > > > On Dec 12, 4:07 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > I still do not see why you cannot use IS_NOT_IN_DB(sqlset,....) You > > > > must have access to the variables that you want to validate. > > > > Correct me if I am wrong but IS_NOT_IN_DB only looks at the value of > > > one field. > > > From validators.py: > > > rows=self.dbset(field=value).select(limitby=(0,1)) > > > > What we are thinking is: > > > [field1value,field2value,field3value,...] as a row is not in the DB. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---