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.