Reputation: 47
my table:
db.define_table('problem',
Field('title','string',unique=True,length=255),
Field('description','text',notnull=False,default=''),
Field('in_date','datetime',notnull=False,default=request.now),
Field('input','text',notnull=False,default=''),
Field('result','text',notnull=False,default=''),
Field('defresult','text',notnull=False),
Field('submit','integer',notnull=False,default=0),
Field('solved','integer',notnull=False,default=0),
Field('pass_rate','decimal(2,2)',notnull=True,default =0.00),
format = '%(title)s')
Insert a record into problem table by sqlform,how to acquire the result field of problem in sqlform dynamically.
def test():
user_id=_get_user_id(auth)
id=request.args(0,cast=int)
for row in db(db.belongs.id==id).select():
taskid=row.task_id
problemid=row.problem_id
record=db.problem(problemid) or redirect(URL('index'))
fields=['title','description','input','result']
form=SQLFORM(db.problem,record,readonly=False,fields=fields)
if form.process().accepted:
db(db.problem.id==problemid).update(submit=db.problem.submit+1)
if(form.vars.result==db.problem.defresult):
The last line I want to judge if the result field is equal to the defresult field. The form.vars.result seems not change even I input another value into sqlform and the values insert before have fill the sqlform after I reloading the page. how to clear the sqlform? Thanks!
Upvotes: 0
Views: 507
Reputation: 25536
form.vars.result
does contain the new value. The problem is that in form.vars.result==db.problem.defresult
, you are comparing that value to a Field
object rather than to the actual value from the record. Earlier, you have:
record=db.problem(problemid)
So, your equality test should be:
if form.vars.result == record.defresult:
Upvotes: 1