在注册.学校模型中
def action_count_student(self):
return {
'name': 'action',
'type': 'ir.actions.act_window',
'view_mode': 'tree,form,search',
'res_model': 'registration.student',
'res_id': self.id,
}
registration.school 模型的 xml 文件
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="object" name="action_count_student" icon="fa-graduation-cap" >
<field name="count" string="Student" widget="statinfo"/>
</button>
<button class="oe_stat_button" type="object" name="action_count_teacher" icon="fa-teacher" >
<field name="count_teacher" string="Teacher" widget="statinfo"/>
</button>
</div>
它显示registration.student 表中存在的学生人数。 但单击统计按钮后,它应该仅显示与该学校相关的学生数据。因为学校和学生之间是一对多的关系。但它显示了学生模型中存在的所有学生记录。怎么解决呢。有人吗?
最佳答案
添加域以过滤您的操作中的记录
@api.multi
def action_count_student(self):
self.ensure_one()
return {
'name': 'action',
'type': 'ir.actions.act_window',
'view_mode': 'tree,form', # and remove search because it appears automatically in searchable view like tree view
'res_model': 'registration.student',
# id don't know the name of m2o in student registration is assumed it's school_id
'domain': [('school_id', '=', self.id)],
'res_id': self.id,
}
关于python - 单击统计按钮后如何过滤与同一型号相关的特定记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56785850/