检索相同 table 的乘法 ID

Retrieving multiply ids of same table

所以每个合作伙伴都有我在我的方法中添加到列表 fields 中的这些字段。这些字段是具有共同模型 'product.category' 的 many2one 字段,因此它们在相同的 table 中。如何检索当前合作伙伴的所有此字段的 ID?

class ClientPotential(models.Model):
    _name = 'client.potential'
    _description = 'Client Potential'
    partner_id = fields.Many2one(
            'res.partner', string='Client')

@api.onchange('partner_id', 'categ_id')
    def _calculate_potential(self):
        categ_obj = self.env['product.category']
        fields = ['flexible_id', 'flexible_qty', 'drawer_id', 'drawer_qty',
                  'runner_id', 'runner_qty', 'group_1_id', 'group_1_qty', 'group_2_id',
                  'group_2_qty', 'group_3_id', 'group_3_qty']

        for field in fields:
            categ_obj += 
        ?????

我认为 getattr 可以解决问题:

    categ_obj = self.env['product.category']
    fields = ['flexible_id', 'flexible_qty', 'drawer_id', 'drawer_qty',
              'runner_id', 'runner_qty', 'group_1_id', 'group_1_qty', 'group_2_id',
              'group_2_qty', 'group_3_id', 'group_3_qty']
    if self.partner_id:
        for field_name in fields:
            categ_obj += getattr(self.partner_id, field_name)

希望你明白了

我爱的男人 python 因为这个。