我想在Many2one
字段中检索模型记录的所有值。我不知道是否可以使用计算机。
我的班级要恢复该值:
class ResPartner_school(models.Model):
_name = 'ecole.partner.school'
_order = 'id desc'
school_name = fields.Many2one(comodel_name="ecole.establishment.webservice",
string="Etablissement Scolaire",
default=1)
school_level = fields.Many2one(comodel_name="ecole.establishment.webservice",
string="Niveau Scolaire",
compute="_get_level")
我的另一堂课:
class SchoolEstablishmentWebServices(models.Model):
_name = 'ecole.establishment.webservice'
_rec_name = "establishment_name"
establishment_name = fields.Many2one(comodel_name="horanet.school.establishment", string="Etablissement Scolaire")
id_establishment = fields.Char(string='idEtablissement')
grade_name = fields.Many2one(comodel_name="horanet.school.grade", string="Niveau Scolaire")
id_class = fields.Char(string='idClasse')
我在班级ResPartner_school
中的功能:
@api.multi
def _get_level(self):
school_level = self.school_name.grade_name
return school_level
如何从类grade_name
的{{1}}字段中检索所有值?
答案 0 :(得分:0)
一种显示“所有”数据(取决于数据量)的解决方案是使用两个变体覆盖模型的name_get()
。
name_get()
首先覆盖模型name_get()
的{{1}}
ecole.establishment.webservice
然后,您需要将值class SchoolEstablishmentWebServices(models.Model):
_name = 'ecole.establishment.webservice'
@api.multi
def name_get(self):
res = []
for webservice in self:
if 'full_name' in self.env.context:
res.append((webservice.id, webservice.get_full_name()))
else:
res.append((webservice.id, webservice.establishment_name))
return res
def get_full_name(self):
# example logic
self.ensure_one()
full_format = "{establishment}, {grade}"
return full_format.format(
establishment=self.establishment_name, grade=self.grade_name)
放入上下文中。您可以将其添加到字段本身,但效果不佳。最好将值放在菜单操作的上下文中,该菜单用于显示full_name
条目。
'ecole.partner.school'