如何在创建表单中具有初始默认值

时间:2013-03-05 15:50:05

标签: openerp

我有这个代表URL书签的类

from openerp.osv import osv, fields

class jbbookmark_jbbookmark(osv.osv):

    _name = "jbbookmark.jbbookmark"
    _description = "Bookmark"

    def default_get(self, cr, uid, fields, context=None):
        res = super(jbbookmark_jbbookmark, self).default_get(cr, uid, fields,     context=context)

        res.update({'name': 'initial value test'})
        res.update({'description': 'initial value test'})
        return res

     _columns = {
         'name': fields.char('URL', required=True, translate=True),
         'description': fields.text('Description'),
         'title': fields.char('Name', size=20, required=True),
    }
     _defaults = {
         'name':'test URL',
    }

我尝试在添加记录时设置表单字段的初始值,但字段只是空白。如何在表单视图中显示这些值

1 个答案:

答案 0 :(得分:3)

您应该将值分配给字典中的键而不是更新。

这肯定会有用。

def default_get(self, cr, uid, fields, context=None):
    res = super(jbbookmark_jbbookmark, self).default_get(cr, uid, fields,     context=context)
    res['name'] = 'initial value test'
    res['description'] = 'initial value test'
    return res