> > I could kind of find a solution to this. If I create a dictionary from the > rows they are easy to manipulate as I want. Although the json data is not > exactly as I asked for, this solution was easier to create: >
db_questions = db( db.question.owner==auth.user.id).select( limitby=(0,5) ) questions_dict = db_questions.as_dict() # find answers to selected questions query = db.self_enquiry_a.id == 0 for question_id in questions_dict.keys(): # build query query |= db.answer.question == int(question_id) # add answers key to questions_dict questions_dict[question_id]["answers"] = [] db_answers = db( query ).select() # created desired dict struct for answer in db_answers.as_list(): question_id = answer['question'] questions_dict[question_id]["answers"].append(answer) json_questions=XML(response.json(questions_dict)) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.