Odoo10 orm操作

查询语句

st = self.env['res.users'].search(['id','=',1])
在res.users表中查找id=1的记录  返回的是一个res.users的对象
print st.name
打印该对象中name

odoologo.png
创建语句

st.create({'name': "测试1" ,'stated': "说明1"})

删除语句

test = self.env['sales_stargets.targetoption']
test.search([('id', '=', 1)]).unlink()

更新语句

rs = demo.search([('name', '=', client_id)])
info = {}
info[‘id’]=1
rs.write(info)

关联查询

student = self.env['emp.student']
teacher = self.env['emp.teacher']
demo = teacher.search([('id', '=', student.search([('id', '=', 1)]).teacher_id.id)])
print demo
print demo.name
print demo.sex

不需要权限限制进行增删改查:(直接在模型后加入sudo())

test = self.env['my.example'].sudo().create({'id':1, 'name': 'test'})
Last modification:January 8th, 2019 at 08:49 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment