2015-03-19 90 views
0

所以它很簡單,我得到添加一個簡單的約束時錯誤(IdentationError:意外的ident),我直接添加於Postgres沒有問題添加SQL由蟒蛇約束

class fleet_site(osv.Model): 

    _name = 'fleet.site' 
    _description = 'Information du site' 
    _order= 'name asc' 
    _columns = { 
     'name': fields.char('Nom', help='Nom du site', required=True), 
     'vehicle_ids': fields.one2many('fleet.vehicle','site_id','Vehicules') 
    } 
     _sql_constraints = [('fleet_site_name_unique','unique(name)', 'Le nom du site existe')] 

回答

0
class fleet_site(osv.Model): 

    _name = 'fleet.site' 
    _description = 'Information du site' 
    _order= 'name asc' 
    _columns = { 
     'name': fields.char('Nom', help='Nom du site', required=True), 
     'vehicle_ids': fields.one2many('fleet.vehicle','site_id','Vehicules') 
    } 
    _sql_constraints = [('fleet_site_name_unique','unique(name)', 'Le nom du site existe')] 

的Python不允許unidented代碼,以便你只需要爲eaxh代碼塊管理相等的空間。我只是從你的代碼中刪除了額外的空格。