I'm wondering just the same. How can this be done in model?. Particularly I want to use IS_IN_DB on a referenced field based on a query filtering by the value of another field of the table.
I've tried this but didn't work: db.table1.field1.requires = lambda x,row: IS_IN_DB(db(db.table2.field2==row. field2)), 'table2.id') Nor did this one: db.table1.field1.requires = IS_IN_DB(db(db.table2.field2==db.table1.field2 )), 'table2.id') where field1 is field of table1: Field('field1', 'reference table2') Regards. El lunes, 16 de septiembre de 2013, 8:49:08 (UTC+2), Hadi Sunyoto escribió: > > from: > http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators > > <http://www.google.com/url?q=http%3A%2F%2Fwww.web2py.com%2Fbooks%2Fdefault%2Fchapter%2F29%2F07%2Fforms-and-validators%23Database-validators&sa=D&sntz=1&usg=AFQjCNE4_4fAPTYEpCZJVvLy1ejv7Tcocw> > > Validators with dependencies > > Usually validators are set once for all in models. > > Occasionally, you need to validate a field and the validator depends on > the value of another field. This can be done in various ways. It can be > done in the model or in the controller. > > > > There is an example validation done in controller but there is no example > validation done in model > > My table: > > db.define_table('config', > Field('config_name', 'string', length=255, required=True, unique=True), > Field('convert_option', 'string', length=255, > requires=IS_IN_SET(CONVERSION, zero=None)), > Field('config_value', 'string', length=255, required=True), > Field('default_value', 'string', length=255, required=True)) > > I want to validate if config_value is greater than default value (for > example), but i don't want to do it in SQLFORM or FORM. > > or is it a bad idea to put validation that depend on other fields in > "model" rather than form? > > Thank you > > Hadi > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.