Skip to Content
Menu
This question has been flagged
1 Reply
5975 Views

Hello,

I have created many2many field, which can contain many elements :

capture_ref = fields.Many2many('affichage.information', string="Numéro de série", required=True)

I would like to browse the these elements in order to can apply my search function :

rec = self.env['affichage.information'].search([('reference', '=', self.capture_ref.reference)])
Avatar
Discard
Best Answer

For version 10. You need to declare your many2many field as like this

class Sample1(models.Model):

     _name = 'sample.sample1'

   field = fields.Many2many('sample.sample2', 'sample1_sample2_rel', 'sample1_id', 'sample2_id', string="Sample1 Field")


class Sample2(models.Model):

     _name = 'sample.sample2'

    s2_field = fields.Char(string="Sample2 Field")


#here you need to declare 'sample1_sample2_rel' as your many2many relationship table and the fields belong to that table

from that you can obtain records by using this

self.env.cr.execute('SELECT * from sample1_sample2_rel where sample1_id= %s' % pass_variable_or_value_here)

res = self.env.cr.fetchall()

print 'res', res


I hope this helps.


     


Avatar
Discard