I'm trying to create a simple relation in openerp with phyton. I have two tables: one for courses(cursos) and other for teachers (profesores) and I need to create a one2many relation between profesores and cursos, so 1 profesor it teach many cursos and many course can be assigned to a teacher.
I've added a widget="selection" in profesor form, so I can select a course, but when I try to save, appears this error: TypeError: 'int' object is not iterable
This is my code:
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'),
}
profesor()
class curso(osv.osv):
_name = 'educacion.curso'
_description = 'Esta clase representa un curso'
_columns = {
'name': fields.char('Curso', size=64, required=True),
'aula': fields.char('Aula', size=200, required=False),
'creditos': fields.char('creditos', size=64, required=False),
'profesor_id': fields.many2one('educacion.profesor', 'Profesores'),
}
curso()
<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>
Thanks