Odoo Help

0

How to implement foreign key in open erp

By
Anuradha
on 11/5/13, 7:02 AM 1,699 views
Hi,
I am new to openerp , I have two table master and details , i want to use id of master as foreign key in detail table.
How can i achieve this?
my code is

from osv import osv,fields
class wlan_master(osv.osv):
    _name = 'wlan_master'
    _columns = {
        'AP_name'       :fields.char(),
        'description'   :fields.char(),
        'ip_address'    :fields.char(),
    }
class wlan_details(osv.osv):
    _name = 'wlan_details'
    _columns = {
        'wireless_workmode'     :fields.char(),
        'enable_wireless'       :fields.char(),
        'ssid'                  :fields.char(),
        'channel'               :fields.char(),
        'wireless_mode'         :fields.char(),
        'channel_bandwidth'     :fields.char(),
        'rate'                  :fields.char(),
        'broadcast_ssid'        :fields.char(),
        'client_isolation'      :fields.char(),
        'wmm_announcement'      :fields.char(),
        'fragement_threshold'   :fields.char(),
        'rts'                   :fields.char(),
        'dtim_gap'              :fields.char(),
        'beacon_gap'            :fields.char(),
        'preamble_type'         :fields.char(),
        'encryption_mode'       :fields.char(),
        'filter_mode'           :fields.char(),
    }
1
Grover Menacho
On 11/5/13, 8:51 AM

Basically you have to do two things:

from osv import osv,fields
class wlan_master(osv.osv):
    _name = 'wlan.master'
    _columns = {
        'AP_name'       :fields.char(),
        'description'   :fields.char(),
        'ip_address'    :fields.char(),
        'defail_ids': fields.one2many('wlan.details','master_id', 'Details')
    }
class wlan_details(osv.osv):
    _name = 'wlan.details'
    _columns = {
        'master_id': fields.many2one('wlan.master', 'Master'),
        'wireless_workmode'     :fields.char(),
        'enable_wireless'       :fields.char(),
        'ssid'                  :fields.char(),
        'channel'               :fields.char(),
        'wireless_mode'         :fields.char(),
        'channel_bandwidth'     :fields.char(),
        'rate'                  :fields.char(),
        'broadcast_ssid'        :fields.char(),
        'client_isolation'      :fields.char(),
        'wmm_announcement'      :fields.char(),
        'fragement_threshold'   :fields.char(),
        'rts'                   :fields.char(),
        'dtim_gap'              :fields.char(),
        'beacon_gap'            :fields.char(),
        'preamble_type'         :fields.char(),
        'encryption_mode'       :fields.char(),
        'filter_mode'           :fields.char(),
    }

This adds a foreign key to details and this make a proper link to master.

0
Antanas
On 11/5/13, 7:30 AM

I think you haven't read documentation yet

class wlan_details(osv.osv):
    _name = 'wlan_details'
    _columns = {
       'master_id': fields.many2one('wlan_master',  'Master'),
       'wireless_workmode'     :fields.char(),
       etc...

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 11/5/13, 7:02 AM
Seen: 1699 times
Last updated: 3/16/15, 8:10 AM