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

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.

主站蜘蛛池模板: 阿克陶县| 河北区| 祁连县| 江都市| 玉林市| 高青县| 托克托县| 石屏县| 龙陵县| 铅山县| 屏山县| 岢岚县| 大竹县| 青河县| 文登市| 毕节市| 明水县| 新郑市| 远安县| 灯塔市| 农安县| 桦甸市| 依安县| 西乌珠穆沁旗| 祁阳县| 错那县| 昭觉县| 邵阳县| 会昌县| 德安县| 上虞市| 伊金霍洛旗| 都昌县| 运城市| 鹤庆县| 滨州市| 柏乡县| 革吉县| 长海县| 皋兰县| 乐陵市|