• 1093 views
  • 0 comments
  • loading...

IS_NOT_IN_DB()

As with all other validators this requirement is enforced at the form processing level, not at the database level. This means that there is a small probability that, if two visitors try to concurrently insert records with the same value (person.name), this results in a race condition and both records are accepted. It is therefore safer to also inform the database that this field should have a unique value:












db.define_table('person', Field('name', unique=True))

db.person.name.requires = IS_NOT_IN_DB(db, 'person.name')

# The following code, for example, does not allow registration of two persons with the same name within 10 days of each other:

import datetime
now = datetime.datetime.today()
db.define_table('person',
Field('name'),
Field('registration_stamp', 'datetime', default=now))
recent = db(db.person.registration_stamp>now-datetime.timedelta(10))
db.person.name.requires = IS_NOT_IN_DB(recent, 'person.name')

Attributes / Arguments

Sets the query

recent = db(db.person.registration_stamp>now-datetime.timedelta(10))
db.person.name.requires = IS_NOT_IN_DB(recent, 'person.name')

Record field

recent = db(db.person.registration_stamp>now-datetime.timedelta(10))
db.person.name.requires = IS_NOT_IN_DB(recent, 'person.name')


IS_NOT_IN_DB('...', error_message='value already in database or empty','...')


IS_NOT_IN_DB('...', allowed_override=['Tom','Jerry'], '...')


IS_NOT_IN_DB('...',  ignore_common_filters=True)


Examples

loading...

Sources / Reference

" Web2py Book"


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)