“int”对象在one2many/manyOne关系中不可iterable

2024-05-17 00:51:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在openerp和phyton建立一个简单的关系。我有两个表:一个是课程表(cursos),另一个是教师表(professors),我需要在professors和cursos之间创建一个2many关系,这样1个profesor它可以教很多cursor,并且许多课程可以分配给一个老师。在

我以profesor的形式添加了widget=“selection”,这样我可以选择一门课程,但是当我试图保存时,出现了一个错误:TypeError:'int'object is not iterable

这是我的代码:


class profesor(osv.osv):
_name = 'educacion.profesor'
_description = 'Esta clase representa un Profesor'
_columns = {
    'nombre': fields.char('Nombre', size=64, required=True),
    'direccion': fields.char('Direccion', size=200, required=False),
    'telefono': fields.char('Telefono', size=64, required=False),
    'email': fields.char('Email', size=200, required=False),
    'cursos_ids': fields.one2many('educacion.curso','profesor_id','Cursos'),
}

教授()

^{pr2}$

卡索()


<record model="ir.ui.view" id="profesores_form">
        <field name="name">profesores_form</field>
        <field name="model">educacion.profesor</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Profesores">
                <field name="nombre"/>
                <field name="direccion"/>
                <field name="telefono"/>
                <field name="email"/>
                <field name="cursos_ids" widget="selection"/>                   
            </form>
        </field>
    </record>

<record model="ir.ui.view" id="cursos_form">
        <field name="name">cursos_form</field>
        <field name="model">educacion.curso</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Cursos">
                <field name="name"/>
                <field name="aula"/>
                <field name="creditos"/>
            </form>
        </field>
    </record>

谢谢


Tags: nameformidfalsefieldfieldssizemodel
1条回答
网友
1楼 · 发布于 2024-05-17 00:51:53

我认为问题是小部件selection。Widgetselection仅用于将manyOne字段转换为选择框,因此用户无法对其进行编辑。因此,将widgetselection用于one2many字段可能会意外地返回与普通one2many字段返回的值类型不同的值。通常,one2many字段将具有以下格式的特殊命令,用于添加/替换/删除记录:

(0, 0,  { values })    link to a new record that needs to be created with the given values dictionary
(1, ID, { values })    update the linked record with id = ID (write *values* on it)
(2, ID)                remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID)                cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID)                link to existing record with id = ID (adds a relationship)
(5)                    unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

相关问题 更多 >