ir.model.fields

Provides information about the fields of Odoo models and allows adding custom fields without using Python code

model_id

Many2one to ir.model to which the field belongs

name

the field’s technical name (used in read or write)

field_description

the field’s user-readable label (e.g. string in fields_get)

ttype

the type of field to create

state

whether the field was created via Python code (base) or via ir.model.fields (manual)

required, readonly, translate

enables the corresponding flag on the field

groups

field-level access control, a Many2many to res.groups

selection, size, on_delete, relation, relation_field, domain

type-specific properties and customizations, see the fields documentation for details

Note

Like custom models, only new fields created with state="manual" are activated as actual fields on the model.

Warning

computed fields can not be added via ir.model.fields, some field meta-information (defaults, onchange) can not be set either

Example

  1. Create x_custom 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','state':'manual'} HTTP/1.1
Host: {your_Odoo_server_url}

JSON Response:

HTTP/1.1 200 OK

{
  'Models': {
      'id': 105,
      'name': 'Custom Model',
      'model': 'x_custom',
      'state': 'manual'
      ...
      ...
      ...
  }
}

XML Response:

HTTP/1.1 200 OK

<Models type="dict">
	<id type="int">105</id>
	<name type="str">Custom Model</name>
	<model type="str">x_custom</model>
	<state type="str">manual</state>
</Models>
  1. Create x_name field record in ir.model.fields object using Create Records API endpoint.

Request:

POST /restapi/1.0/object/ir.model.fields?vals={'model_id':105,'name':'x_name','ttype':'char','state':'manual','required':True} HTTP/1.1
Host: {your_Odoo_server_url}

JSON Response:

HTTP/1.1 200 OK

{
  'Fields': {
      'id': 210,
      'name': 'x_name',
      'model_id': [105, 'Custom Model'],
      'ttype': 'char',
      'state': 'manual',
      'required': True
      ...
      ...
      ...
  }
}

XML Response:

HTTP/1.1 200 OK

<Fields type="dict">
	<id type="int">210</id>
	<name type="str">x_name</name>
	<model_id type="list">
		<item type="int">105</item>
		<item type="str">Custom Model</item>
	</model_id>
	<ttype type="str">char</ttype>
	<state type="str">manual</state>
	<required type="bool">true</required>
</Fields>
  1. Create test record record in x_custom object using Create Records API endpoint.

Request:

POST /restapi/1.0/object/x_custom?vals={'x_name':'test record'} HTTP/1.1
Host: {your_Odoo_server_url}

JSON Response:

  1. HTTP/1.1 200 OK
    
    {
      'Custom Model': {
          'id': 115,
          'x_name': 'test record',
          'display_name': 'test record',
          'create_date': '2017-07-15 14:31:17',
          'create_uid': [1, 'Administrator'],
          'write_date': '2017-07-15 14:31:17',
          'write_uid': [1, 'Administrator'],
          ...
          ...
          ...
      }
    }
    

XML Response:

HTTP/1.1 200 OK

<x_custom type="dict">
	<id type="int">115</id>
	<x_name type="str">test record</x_name>
	<display_name type="str">test record</display_name>
	<create_date type="str">2017-07-15 14:31:17</create_date>
	<create_uid type="list">
		<item type="int">1</item>
		<item type="str">Administrator</item>
	</create_uid>
	<write_date type="str">2017-07-15 14:31:17</write_date>
	<write_uid type="list">
		<item type="int">1</item>
		<item type="str">Administrator</item>
	</write_uid>
</x_custom>

Last updated