0

I have two tables:

db.define_table('tests', Field('name'), Field('status'),...)
db.tests.status.requires=IS_IN_SET(['OK','obsolete'])
db.define_table('testruns', Field('name'), Field('test', db.tests), ...)

My form looks lik this:

form = SQLFORM(db.testruns)

How can I change the form, that it contains only the tests that have the state 'OK'?

4

1 回答 1

1

当您定义一个像 的引用字段Field('test', db.tests)时,它会获得一个默认IS_IN_DB验证器,它会在表单中为其提供一个默认选择小部件。验证器默认为引用字段中的IS_IN_DB所有记录,但您可以显式指定自己的IS_IN_DB验证器并传入将记录限制为子集的 DAL Set 对象(在这种情况下,那些具有 tests.status == 'OK' 的记录):

db.define_table('testruns',
    Field('name'),
    Field('test', db.tests,
          requires=IS_IN_DB(db(db.tests.status == 'OK'), 'tests.id', '%(name)s'),
          represent=lambda id, row: db.tests[id].name))
于 2012-07-24T14:29:59.153 回答