Provides information about Odoo models via its various fields
name
a human-readable description of the model
model
the name of each model in the system
state
whether the model was generated in Python code (base
) or by creating an ir.model
record (manual
)
field_id
list of the model’s fields through a One2many to ir.model.fields
view_ids
One2many to the Views defined for the model
access_ids
One2many relation to the Access Control set on the model
Note
ir.model
can be used to:
query the system for installed models (as a precondition to operations on the model or to explore the system’s content)
get information about a specific model (generally by listing the fields associated with it)
create new models dynamically over REST API
Warning
custom model names must start with x_
the state
must be provided and manual
, otherwise, the model will not be loaded
it is not possible to add new methods to a custom model, only fields
Example
Create x_custom_model
model record in ir.model
object using Create Records API endpoint.
Request:
POST /restapi/1.0/object/ir.model?vals={'name':'Custom Model','model':'x_custom_model','state':'manual'} HTTP/1.1
Host: {your_Odoo_server_url}
JSON Response:
HTTP/1.1 200 OK
{
'Models': {
'id': 104,
'name': 'Custom Model',
'model': 'x_custom_model',
'state': 'manual'
...
...
...
}
}
XML Response:
HTTP/1.1 200 OK
<Models type="dict">
<id type="int">104</id>
<name type="str">Custom Model</name>
<model type="str">x_custom_model</model>
<state type="str">manual</state>
</Models>
Request:
GET /restapi/1.0/object/x_custom_model/fields_get?attributes=['string','help','type'] HTTP/1.1
Host: {your_Odoo_server_url}
JSON Response:
Note
a custom model will initially contain only the “built-in” fields available on all models
HTTP/1.1 200 OK
{
'fields': {
'create_uid': {
'type': 'many2one',
'string': 'Created by'
},
'create_date': {
'type": 'datetime',
'string': 'Created on'
},
'__last_update': {
'type': 'datetime',
'string': 'Last Modified on'
},
'write_uid': {
'type': 'many2one',
'string': 'Last Updated by'
},
'write_date': {
'type': 'datetime',
'string': 'Last Updated on'
},
'display_name': {
'type': 'char',
'string': 'Display Name'
},
'id": {
'type': 'integer',
'string': 'Id'
}
}
}
XML Response:
HTTP/1.1 200 OK
<fields type="dict">
<create_uid type="dict">
<type type="str">many2one</type>
<string type="str">Created by</string>
</create_uid>
<create_date type="dict">
<type type="str">datetime</type>
<string type="str">Created on</string>
</create_date>
<__last_update type="dict">
<type type="str">datetime</type>
<string type="str">Last Modified on</string>
</__last_update>
<write_uid type="dict">
<type type="str">many2one</type>
<string type="str">Last Updated by</string>
</write_uid>
<write_date type="dict">
<type type="str">datetime</type>
<string type="str">Last Updated on</string>
</write_date>
<display_name type="dict">
<type type="str">char</type>
<string type="str">Display Name</string>
</display_name>
<id type="dict">
<type type="str">integer</type>
<string type="str">Id</string>
</id>
</fields>