Field('is_correct', 'boolean', default=False)
In the form you get a checkbox widget unless you choose otherwise.
In the controller:
if form.vars.is_correct:
# do something
else:
#do otherwise
Less typing.
Also, look in your database back end and see how it represents the values.
You will find they are surrounded by pipe characters. Web2py is using
them for list separators because it expects you to store multiple values in
the field.
Is that what you want to do?
On Friday, March 8, 2013 3:09:55 AM UTC-5, Mika Sjöman wrote:
>
> Huge thanks!
> That worked!
>
> Den fredagen den 8:e mars 2013 kl. 12:45:34 UTC+8 skrev weheh:
>>
>> What kind of error message are you getting?
>>
>> I assume the request.vars['lesson'] and request.vars.answer are both
>> indices into their respective tables. However, request.vars will be holding
>> these values as strings. Without knowing more, I would suggest putting an
>> int() around those two vars, as in:
>>
>> answer = db.answer[int(request.vars.answer)]
>>
>> and then do your test:
>>
>> if 'y' in answer.is_correct:
>> # do something
>> else:
>> # do something else
>>
>> Hope this helps.
>>
>> On Friday, March 8, 2013 12:37:20 PM UTC+8, Mika Sjöman wrote:
>>>
>>> Hi trying to check true false in a string set, but does not work
>>>
>>> ## db.py
>>>
>>> db.define_table('answer',
>>> Field('description'),
>>> Field('is_correct', type='list:string'),
>>> Field('belongs_to_quiz',type='reference quiz',writable=False),
>>> )
>>> db.answer.is_correct.requires=IS_IN_SET(('y','n'))
>>>
>>> ## controller
>>>
>>> def check_if_correct_answer():
>>> """this function tests if the user answers correctly to a question
>>> and sends back a ajax response """
>>> lesson = db.lesson(request.vars['lesson'])
>>> answer = db.answer(request.vars.answer)
>>> if answer.is_correct == "y":
>>> #db.user_answer.insert(belongs_to_user=auth.user.id,
>>> belongs_to_lesson=lesson.id, correct='y')
>>> correct_or_not='y'
>>> else:
>>> correct_or_not='n'
>>> return "jQuery('.flash').html('%s').slideDown();" % (correct_or_not)
>>>
>>>
>>> But this test with answer.is_correct does not work. Anybody has an idea
>>> on how to check?
>>>
>>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.