Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4414 Lượt xem

Hello! I'm new in Odoo and I don't understand how to use ORM.  


Previously, I worked on Django and for get or create record you have to:

1. Import model, like: from app.models import TestModel

2. Get record with id=1: TestModel.objects.get(id=1)

3. Create new record: 1) test_model = TestModel(...) 2) test_model.save()


Here, in Odoo is any posibility to do like that?

My task is:

1. To get record, for example, by id

2. Receive data from external endpoint and save it in Model ProductCategory. I want to do it via script.


Thank you in advance for your help )

Ảnh đại diện
Huỷ bỏ

1. To get record(s) by ID: self.env['model_name'].browse(id or list of ids)
2. To save it in product category:
for r in data_from_external_endpoint:
self.env['product.category'].create({'name':'new category name','parent_id':id_of_parent})

They have great documentation here: https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html . Also i recomend you spend sometimes reading through some OCA or Odoo model codes to get the hang of it.

Câu trả lời hay nhất

Hi,

The following resources will be useful to you for understanding ORM Concepts.

https://www.cybrosys.com/blog/orm-methods-in-odoo-15

https://www.cybrosys.com/blog/orm-in-odoo

https://www.cybrosys.com/blog/common-orm-methods

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 24
1254
1
thg 7 24
2085
1
thg 3 22
4866
1
thg 6 21
3245
0
thg 3 21
2030