2

我有一个代表 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',
    }

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

4

1 回答 1

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
于 2013-03-06T04:54:33.127 回答