Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3272 Lượt xem

I created a controller to fetch records from students table for logged parent user. 

class Webopeneducat(http.Controller):
    @http.route('/my/child', auth='user', website=True)
    def list_students(self, **kw):
        current_user = http.request.env.context.get('uid')
        students = request.env['op.student'].sudo().search([('parent_ids.user_id', '=', current_user)])
        assignments = request.env['op.assignment'].sudo().search(['student[].student_id', 'in', 'allocation_ids'])
        print("students---", students)
        return http.request.render('web_openeducat.index', {

            'students': students,
            'assignments': assignments
            })

I want to obtain records of only logged user. I can get students info from students model, but i also want assignments info of that students from assignments model. how can i fetch data from multiple models at once?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

If you have the record set of the student in the students varibale and if you need to fetch the assignment records of this student, you can do it like this,

assignments = request.env['op.assignment'].sudo().search([('student_id', 'in',  students.ids)]) 

Thanks

Ảnh đại diện
Huỷ bỏ