Field edition
Data which is specific to a record should be saved on that record, so let us add a new biography field to our teachers:
academy/models.py
_name = 'academy.teachers'
name = fields.Char()
biography = fields.Html()
academy/templates.xml
<div class="oe_structure">
<div class="container">
<h3><t t-esc="person.name"/></h3>
<div><t t-esc="person.biography"/></div>
</div>
</div>
<div class="oe_structure"/>
Restart Odoo and update the views, reload the teacher's page and… the field is invisible since it contains nothing.
For record fields, templates can use a specialt-field
directive which allows editing the field content from the website using field-specific interfaces. Change the_person_template to uset-field
:
academy/templates.xml
<div class="oe_structure"/>
<div class="oe_structure">
<div class="container">
<h3 t-field="person.name"/>
<div t-field="person.biography"/>
</div>
</div>
<div class="oe_structure"/>
Restart Odoo and upgrade the module, there is now a placeholder under the teacher's name and a new zone for blocks inEditmode. Content dropped there is stored in the corresponding teacher'sbiography
field, and thus specific to that teacher.
The teacher's name is also editable, and when saved the change is visible on the index page.
t-field
can also take formatting options which depend on the exact field. For instance if we display the modification date for a teacher's record:
academy/templates.xml
<div class="oe_structure">
<div class="container">
<h3 t-field="person.name"/>
<p>Last modified: <i t-field="person.write_date"/></p>
<div t-field="person.biography"/>
</div>
</div>
it is displayed in a very "computery" manner and hard to read, but we could ask for a human-readable version:
academy/templates.xml
<div class="oe_structure">
<div class="container">
<h3 t-field="person.name"/>
<p>Last modified: <i t-field="person.write_date" t-options='{"format": "long"}'/></p>
<div t-field="person.biography"/>
</div>
</div>
or a relative display:
academy/templates.xml
<div class="oe_structure">
<div class="container">
<h3 t-field="person.name"/>
<p>Last modified: <i t-field="person.write_date" t-options='{"widget": "relative"}'/></p>
<div t-field="person.biography"/>
</div>
</div>