This question has been flagged
1 Reply
8808 Views

In models.py, i use following code to create an object. Please ignore all Chinese characters in this page.

class Assemblies(models.Model):

_name = 'property.assemblies'

name = fields.Char(string = '电脑名称')

operator = fields.Char(string = '操作人')

person = fields.Char(string = '使用人')

components = fields.Many2many(comodel_name='property.models', relation='property_assembly_rel', string = '组件')

Now I can see the property_assembly_rel table in odoo's postgreSQL database, but I want to modify this table (insert, write...).

I want to use assemblies_rel_obj = http.request.registry['property.hehe']  to get that table object, but unluckily, I know the table name is property_assembly_rel while I don't know the object name of the table.

Can anyone help me? Many thanks!


Avatar
Discard
Best Answer
  • if you want to insert in the record of many2many or i say want to insert a record in property_assembly_rel  
    form controller 
     then  you should use  http.request.registry['property.assemblies'] in odoov7 and  

    http.request.env['property.assemblies'] in odoov8 and odoov9

    Follow these pattern :


  • (0, 0, { values }) link to a new record

  • (1, ID, { values }) update  the linked record with id = ID (write values on it)

  • (2, ID) remove and delete the linked record  with id = ID

  • (3, ID) cut the link to the linked record with id = ID

  • (4, ID) link to existing record with id = ID

  • (5) unlink all

  • (6, 0, [IDs]) replace the list of linked IDs

  •  

try this link for more info https://www.odoo.com/documentation/8.0/reference/orm.html


Avatar
Discard
Author

Thanks! this perfectly solve my problem.