2017-03-16 13 views
1

私はphytonで簡単なリレーションをopenerpに作成しようとしています。私は2つのテーブルを持っています:1つはコース(cursos)用、もう1つは教師用(profesores)です。プロフェッショナルとcursosの間にはたくさんの関係を作成する必要があるので、1人の教授が多数のcursosを教え、多くのコースは教師に割り当てられます。'int'オブジェクトはone2many/many2oneのリレーションでは反復できません

私はprofesorの形でウィジェット=「選択」を追加しましたので、私はコースを選択することができますが、私が保存しようとすると、このエラーが表示されます:例外TypeError:「int型のオブジェクトは、反復可能な

これではありません私のコードです:


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()

012私は問題がウィジェット selectionだと思う
<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> 

おかげ

答えて

0

。ウィジェットselectionはmany2oneフィールドでのみ使用され、many2oneフィールドを選択ボックスに変換してユーザーが編集することはできません。したがって、one2manyフィールドにウィジェットselectionを使用すると、誤って通常の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) 
関連する問題