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

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.

主站蜘蛛池模板: 陕西省| 普格县| 新巴尔虎左旗| 安阳县| 城固县| 沽源县| 永济市| 韶山市| 天门市| 峨眉山市| 长武县| 清水河县| 江源县| 屯留县| 横山县| 岳阳县| 扶绥县| 金沙县| 海口市| 邹平县| 兰溪市| 南通市| 芜湖县| 江华| 晋中市| 淮滨县| 沿河| 平山县| 莲花县| 涿鹿县| 杨浦区| 平南县| 喀喇沁旗| 武清区| 海阳市| 永善县| 宣威市| 黔西| 宁远县| 永兴县| 夏河县|