Dropdown Data from DB

  • Step 1:

    In model

    
                      
                       class department(osv.osv):
            _name = 'department'
    
            _columns = {
                     'name': fields.char('Department', size=32, required=True),
            }
    
        class djelatnik(osv.osv):
            _name = 'employee'
    
            _columns = {
                'name': fields.char('name',size=30, required=True, help='name'),
                'surname': fields.char('surname', size=30, required=True, help='surname'),
                'odjel': fields.many2one('department' ,'Departments')           
            }  
                

    in view

    
                <record model="ir.ui.view" id="view_employee_form">
                <field name="name">employee.form</field>
                <field name="model">employee</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="employee">                   
                        <field name="name" select="1"/>
                        <field name="surname" select="2"/>
                        <field name="odjel" select='0'/>
                    </form>
                </field>
            </record>
            <record model="ir.ui.view" id="view_employee_tree">
                <field name="name">employee.tree</field>
                <field name="model">employee</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="employee">
                        <field name="name"/>
                        <field name="surname"/>
                         <field name="odjel"/>
                    </tree>
                </field>
            </record>
            <record model="ir.actions.act_window" id="action_employee">
                <field name="name">employee</field>
                <field name="res_model">employee</field>
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
                <field name="context">{"search_default_type_date":0}</field>
            </record>
            <menuitem name="HR/HR" id="menu_employee" action="action_employee"/>
            <menuitem name="employee" id="menu_employee_employee_item" parent="menu_employee" action="action_employee"/>
    
            <record model="ir.ui.view" id="view_department_form">
                <field name="name">department.form</field>
                <field name="model">department</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="department">                   
                        <field name="name" select="1"/>
                    </form>
                </field>
            </record>
            <record model="ir.ui.view" id="view_department_tree">
                <field name="name">department.tree</field>
                <field name="model">department</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="odjel">
                        <field name="name"/>
                    </tree>
                </field>
            </record>
            <record model="ir.actions.act_window" id="action_department">
                <field name="name">department</field>
                <field name="res_model">department</field>
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
            </record>
            <menuitem name="department" id="menu_department_department_item" parent="menu_employee" action="action_department"/>