官术网_书友最值得收藏!

Creating Views

We have created the Books model and made it available in the user interface with a Menu Item. Next, we will be creating the two essential views for it: a list (also called a tree) and a form.

In Settings, navigate to Technical | User Interface | Views and create a new record with the following values:

  • View Name: Books List View
  • View Type: Tree
  • Model: x_library_book

In the Architecture tab, we should write XML with the view structure. Use the following XML code:

<tree>
<field name="x_name" />
<field name="x_author_ids" widget="many2many_tags" />
</tree>

The basic structure of a list view is quite simple: a <tree> element containing one or more <field> elements for each of the columns to display in the list view. We added the widget attribute to the Authors field, to have it presented as button-like tags.

We can do a few more interesting things with list views, and will explore them in more detail in Chapter 9, Backend Views – Design the User Interface.

Next, we will create the form view. Create another new record, and use the following values:

  • View Name: Books Form View
  • View Type: Form
  • Model: x_library_book

In the Architecture tab, type the following XML code:

<form>
<group>
<field name="x_name" />
<field name="x_author_ids"
widget="many2many_tags"
context="{'default_x_is_book_author': True}" />
</group>
</form>

The form view structure has a root <form> element, containing elements such as <field>, among others that we will learn about in Chapter 9, Backend Views – Design the User Interface. Here, we also chose a specific widget for the Authors field, to be displayed as tag buttons instead of a list grid. We also added a context attribute, so that when new Authors are created directly from here, they will already have the Is Book Author checkbox enabled.

主站蜘蛛池模板: 东光县| 固原市| 京山县| 西藏| 正定县| 安远县| 昭苏县| 舟曲县| 大足县| 临泉县| 西乌珠穆沁旗| 徐闻县| 罗山县| 灵石县| 东阿县| 正蓝旗| 中宁县| 永丰县| 富宁县| 德安县| 荔波县| 紫金县| 满洲里市| 佛山市| 巴马| 六安市| 德庆县| 吉木乃县| 永修县| 新泰市| 河西区| 瑞安市| 临桂县| 修文县| 冀州市| 江山市| 沾益县| 邯郸县| 望江县| 修水县| 鞍山市|