Browse Source

[IMP] doc: better xpath example

The xpath syntax `"//selector` is mostly used in Odoo, is clearer on the meaning
and more flexible about view changes.
Give an example with the mostly used syntax.

Add a tip to indicate the shorter xpath syntax
master
Martin Trigaux 6 years ago
parent
commit
b4b373c965
  1. 20
      doc/howtos/backend.rst

20
doc/howtos/backend.rst

@ -626,9 +626,9 @@ instead of a single view its ``arch`` field is composed of any number of
<field name="model">idea.category</field>
<field name="inherit_id" ref="id_category_list"/>
<field name="arch" type="xml">
<!-- find field description inside tree, and add the field
<!-- find field description and add the field
idea_ids after it -->
<xpath expr="/tree/field[@name='description']" position="after">
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" string="Number of ideas"/>
</xpath>
</field>
@ -652,6 +652,22 @@ instead of a single view its ``arch`` field is composed of any number of
alters the attributes of the matched element using special
``attribute`` elements in the ``xpath``'s body
.. tip::
When matching a single element, the ``position`` attribute can be set directly
on the element to be found. Both inheritances below will give the same result.
.. code-block:: xml
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" />
</xpath>
<field name="description" position="after">
<field name="idea_ids" />
</field>
.. exercise:: Alter existing content
* Using model inheritance, modify the existing *Partner* model to add an

Loading…
Cancel
Save