Odoo Help

Welcome!

This community 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.

0

How to implement foreign key in open erp

By
Anuradha
on 11/5/13, 7:02 AM 1,331 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

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

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...

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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