1
db.define_table('mytable',
    Field('start_number', 'double', requires=IS_NOT_EMPTY()),
    Field('current_number', 'double', default=mytable.start_number, requires=IS_NOT_EMPTY()))

When something happens on the website, current_number can be changed to something else, but will always start with the default value of start_number (ie, when the entry is created). Each entry has a different start_number.

I keep getting an error saying that mytable can't be found, probably because it hasn't been fully defined yet. Is it still possible to set the default value of current_number to start_number?

4

1 回答 1

0

如果插入总是通过表单提交完成,你可以这样做:

Field('current_number', 'double', default=request.post_vars.start_number, ...)

另一种选择是使其成为计算域:

Field('current_number', 'double', compute=lambda r: r.start_number, ...)

但是,默认情况下,计算字段不会显示在使用SQLFORM.为无。

于 2013-04-29T16:06:09.480 回答