我有many2one字段的域过滤器代码。为many2many怎么办?

时间:2015-06-19 09:58:56

标签: python openerp odoo

这对于很多2字段工作正常,所以我想'area_id',即 hindu_data_super 类应该在many2many或者请让我知道如何在一个中选择多个项目场...

class hindu_desh(osv.Model):
    _name="hindu.desh" 
    _description="Define districts" 
    _columns={ 'name':fields.char('District Name',size=64,required=True) }
hindu_desh()



class hindu_state(osv.Model): 
    _name="hindu.state" 
    _description="Define sub districts" 
    _columns={ 'name':fields.char('Sub District Name',size=64,required=True), 'hindu_state_id': fields.many2one('hindu.desh','District Name',select=True,required=True,ondelete="restrict") }
hindu_state()


class hindu_dist(osv.Model): 
    _name="hindu.dist" 
    _description="Define areas" 
    _columns={ 'name':fields.char('Area Name',size=64,required=True),
        #'area_type': fields.selection(area_type_lov,'Area Type',required=True), 
        'hindu_state_id':fields.many2one('hindu.state','Sub District Name',size=64,required=True),
           'district_id':fields.related('hindu_state_id','hindu_state_id',readonly=True,type='many2one',relation='hindu.desh',string='District Name'),
}

hindu_dist()



class hindu_data_super(osv.Model): 
    _name = "hindu.data.super" 
    _description = "Area of Registration Super"
    _columns = { 
        'district_id' : fields.many2one('hindu.desh','District', select=True, required=True, ondelete="restrict"), 
        'hindu_state_id' : fields.many2one('hindu.state', 'Sub District', domain="[('hindu_state_id', '=', district_id)]", select=True, required=True),
        'area_id' : fields.many2one('hindu.dist', 'Area', domain="[('hindu_state_id', '=', hindu_state_id)]", select=True, required=True),
    }
hindu_data_super()

1 个答案:

答案 0 :(得分:0)

我已经更改了字段的结构,请检查并尝试一下,hindu.data.super中的area_ids是fields.related,这样你就可以根据状态选择获得所有区域,如果你需要更多,我认为需要更多的工作为此。

class hindu_desh(osv.Model):
    _name="hindu.desh" 
    _description="Define districts" 
    _columns={ 'name':fields.char('District Name',size=64,required=True) }
hindu_desh()


class hindu_state(osv.Model): 
    _name="hindu.state" 
    _description="Define sub districts" 
    _columns={ 
            'name':fields.char('Sub District Name',size=64,required=True), 
            'hindu_state_id': fields.many2one('hindu.desh','District Name',select=True,required=True,ondelete="restrict") }
            'area_ids' : fields.one2many('hindu.dist','hindu_state_id','Areas')
hindu_state()


class hindu_dist(osv.Model): 
    _name="hindu.dist" 
    _description="Define areas" 
    _columns={ 
        'name':fields.char('Area Name',size=64,required=True),
        'hindu_state_id':fields.many2one('hindu.state','Sub District Name',size=64,required=True),
        'district_id':fields.related('hindu_state_id','hindu_state_id',readonly=True,type='many2one',relation='hindu.desh',string='District Name'),
}

hindu_dist()



class hindu_data_super(osv.Model): 
    _name = "hindu.data.super" 
    _description = "Area of Registration Super"
    _columns = { 
        'district_id' : fields.many2one('hindu.desh','District', select=True, required=True, ondelete="restrict"), 
        'hindu_state_id' : fields.many2one('hindu.state', 'Sub District', domain="[('hindu_state_id', '=', district_id)]", select=True, required=True),
        'area_ids' : fields.related('hindu_state_id','hindu_state_id',readonly=True,type='one2many',relation='hindu.dist',string='Area',store=True),
    }
hindu_data_super()