如何将多个模型添加到一个视图? [英] How do I add multiple models to one view?

查看:112
本文介绍了如何将多个模型添加到一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个视图中使用三种不同的模型.我创建了一个新模型,该模型继承了看起来不错的模型.

I'm trying to use three different models in one view. I've created a new model that inherits the models which seems to work fine.

from openerp import models, fields, api

class ProjectNote(models.Model):
    _name = "triangle.project.note"
    _inherit = ["note.note", "project.project", "triangle.note"]

我的问题在视图中.我将新模型用作模型,并从项目继承视图.

My problem is in the view. I use my new model as the model and inherit a view from project.

<record id="view_project_notes_form" model="ir.ui.view">
      <field name="name">triangle.project.note.form</field>
      <field name="model">triangle.project.note</field>
      <field name="inherit_id" ref="project.edit_project"/>
      <field name="arch" type="xml">
        <data>
          <xpath expr="//field[@name='privacy_visibility']" position="replace">
            <h2>
              <field name="title" placeholder="Title"/>
            </h2>
          </xpath>
        </data>
      </field>
    </record>

我没有收到任何错误,但没有添加我的字段.

I don't get any errors but my field is not being added.

感谢您的帮助!

推荐答案

如果您试图打开project.project视图,并且想知道为什么其中没有字段title:不会.您不是在扩展模型project.project的项目视图,而是在为模型triangle.project.note定义一个继承该项目视图的表单视图.

If you're trying to open a project.project view and wondering why there is no field title in it: there can't be. You aren't extending the project view for model project.project but are defining a form view for your model triangle.project.note which inherits the project view.

因此,项目视图保持不变,您刚刚为新模型创建了第一个表单视图.

So the project views are untouched, you've just created the first form view for your new model.

这篇关于如何将多个模型添加到一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆