conditional and validators in db.py

51 views
Skip to first unread message

IoT Engineer

unread,
Mar 8, 2021, 11:53:08 PM3/8/21
to web2py-users

Hai , I have a doubt in web2py model - conditional and validator.

I am making a mobile contact management for customers .

I am using

db.cusReg.cus_phone_number_1.requires = IS_NOT_IN_DB(db, 'cusReg.cus_phone_number_1')

db.cusReg.email_id.requires = IS_NOT_IN_DB(db, 'cusReg.email_id')

to  avoid duplication of phone number and email address


it works well for 1 user ( consider its USER A )


when a new user ( consider its USER B )
 likes to add their customer its violating to add them because it is already added by USER A

so how to make conditional in db.py that makes user 1 and user 2 can add same customer but they can’t repeatedly add it within them ?

Dave S

unread,
Mar 9, 2021, 1:28:10 PM3/9/21
to web2py-users
I think the answer is in Chapter 7,  where 
is the link to the paragraphs on IS_IN_DB  and IS_NOT_IN_DB.  They each have an example that you can use.  The first example shows how to exclude duplicates during a 10 day period using IS_NOT_IN_DB, the second  shows how to use the _and keywrod with IS_IN_DB.  Both validators can use sets (query results) rather than the whole table, and the examples are built on that.

You can also use an onvalidation function
or a custom validator

I would keep reading after the last link for the topics Multiple Validators and Validators with dependencies
but I would think the easiest approach is the _and keyword, since you're going to want to verify that userB is in the DB. 

/dps
 

IoT Engineer

unread,
Mar 10, 2021, 2:07:10 PM3/10/21
to web2py-users
many thanks @snide ; it works well for me; thanks a lot
Reply all
Reply to author
Forward
0 new messages