Thanks Fran... now I think it's more clear in my head...

again, I post my code with the right names...

here's my applications.sefom.modules.validators.py (yes , my
application name is 'sefom') :


from gluon.validators import *

class IS_NOT_IN_DB_DDOWN_UIM(object):

    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_implantee.unit_id==request.vars.unit_id),'u_implantee.zd_id')
(value)
        return e


here's the code I put in my model db.py:


from applications.sefom.modules.validators import *

db.define_table('zonedef',
                SQLField('nom'))

db.zonedef.nom.requires=[IS_NOT_EMPTY(error_message='ne peut être
vide!'),IS_NOT_IN_DB(db,'zonedef.nom')]

db.define_table('u_nommee',
                SQLField('nom'),
                SQLField('description',length=128))

# table des unités
db.define_table('u_implantee',
                SQLField('unit_id',db.u_nommee),
                SQLField('zd_id',db.zonedef"),
                SQLField('nb_u','double'))

db.u_implantee.zd_id.requires=IS_IN_DB(db,'zonedef.id','%(nom)s')
db.u_implantee.unit_id.requires=IS_IN_DB(db,'u_nommee.id','%(nom)s : %
(description)s')

db.u_implantee.zd_id.requires=IS_NOT_IN_DB_DDOWN_UIM(db,'zonedef.id','%
(nom)s')


and here's the error I get :

 File "applications/sefom/modules/validators.py", line 27, in __init__
    IS_IN_DB.__init__(self,*a,**b)
TypeError: unbound method __init__() must be called with IS_IN_DB
instance as first argument (got IS_NOT_IN_DB_DDOWN_UIM instance
instead)

I'm using postgreSQL and I created a multi-column constraint on
(zd_id,unit_id) for 'u_implantee' table. So the duet can't be present
twice.

Is there another solution ?

Thanks a lot for your help.

On 8 jan, 13:43, Fran <francisb...@googlemail.com> wrote:
> On Jan 8, 9:03 am, tknack <tknac...@gmail.com> wrote:
>
> > Is it correct to put my validator code in validator.py ?
>
> I put my custom validators into a separate validators.py in my modules
> folder & then import to the model like so:
> from applications.myapplication.modules.validators import *
>
> F
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to