动态填充下拉列表 [英] Populate DropDown List dynamically

查看:81
本文介绍了动态填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从OpenERP中另一个DDL的值填充我的DDL(选择).这是我尝试过的代码.

I am trying to populate my DDL(selection) from value of another DDL in OpenERP. Here is the code, that i have tried.

这是我的View XML:

Here is my View XML:

<h1>
    <label for="categ1" string="Parent category"/>
         <field name="categ1" on_change="Product_Category_OnChange(categ1)" />
</h1>
<newline/>
<h1> 
    <label for="my_products" string="Products" /> 
         <field name="my_products" />
</h1>

此视图的我的_columns类似于:

_columns = {
     'categ1':fields.many2one('product.category','Parent Category',required=True),
     'my_products':fields.many2one('product.product','Products')
}

我的onchange函数类似于:

def Product_Category_OnChange(self,cr,uid,ids,categ1):
    pro_id={}
    cr.execute('select ... where parent_id='+str(categ1))
    res = cr.fetchall()
    for i in range(len(res)):
            pro_id[i]=res[i]
    return {'domain':{'my_products': pro_id}}

问题是,我没有得到my_products bu的过滤值,而是得到了my_products中的所有值.请让我知道,我做错了什么,或者指出正确的方向.谢谢

The problem is, i am not getting filtered values for my_products bu instead getting all the values that are in my_products. Plz let me know, what i am doing wrong, or point me to the right direction. Thanks

推荐答案

我认为您只想显示该类别下的产品.

I think you want to show only the products that come under that category.

def Product_Category_OnChange(self,cr,uid,ids,categ1, context=None):
    pro_id={}
    product_obj = self.pool.get('product.category')
    if not categ1:return {}
    categ_obj = product_obj.browse(cr, uid, categ1)

    return {'domain':{'my_products':[('categ_id','=',categ_obj.id)]}}

或xml

<field name="my_products" domain="[('categ_id','=',categ1)]" />

这篇关于动态填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆