### 搜索视图 搜索查看` <字段> `元素可以有一个` @ filter_domain `,覆盖在特定领域搜索生成的域。在给定的域中,“自我”代表用户输入的值。在下面的例子中,它是用来搜索两个字段的名称和描述。 搜索视图也可以包含` <filter> `元素,从而作为预定义的搜索切换。过滤器必须具有下列属性之一: `domain` 将给定的域添加到当前搜索 `context` 添加一些背景下,当前的搜索;使用的关键` group_by `在给定的字段名称组结果 ~~~ xml <search string="Ideas"> <field name="name"/> <field name="description" string="Name and description" filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"/> <field name="inventor_id"/> <field name="country_id" widget="selection"/> <filter name="my_ideas" string="My Ideas" domain="[('inventor_id', '=', uid)]"/> <group string="Group By"> <filter name="group_by_inventor" string="Inventor" context="{'group_by': 'inventor_id'}"/> </group> </search> ~~~ 在一个动作中使用非默认搜索视图,它应与使用的行动记录` search_view_id `场。 行动也可以设置默认值为搜索领域通过其`context`领域:形式的` search_default_ * field_name * `将初始化提供的价值 *field_name* 上下文键。搜索过滤器必须有一个可选的`@name`有违约,表现为布尔值(他们只能默认启用)。 练习 搜索视图 1. 添加一个按钮来过滤当前用户在搜索视图中负责的课程。默认选择的。 2. 由负责任的用户添加一个按钮组课程。 *openacademy/views/openacademy.xml* ~~~ xml <search> <field name="name"/> <field name="description"/> <filter name="my_courses" string="My Courses" domain="[('responsible_id', '=', uid)]"/> <group string="Group By"> <filter name="by_responsible" string="Responsible" context="{'group_by': 'responsible_id'}"/> </group> </search> </field> </record> ~~~ ~~~ xml <field name="res_model">openacademy.course</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> <field name="context" eval="{'search_default_my_courses': 1}"/> <field name="help" type="html"> <p class="oe_view_nocontent_create">Create the first course </p> ~~~