跳至內容
選單
此問題已被標幟
1 回覆
6610 瀏覽次數

hi all

i need to create unique python constraint (by convert this sql constraint) to be applied for all records
_sql_constraints = [
        ('unique_mobile', 'unique (mobile)', 'Mobile number already exists!')
    ]
Thanks

頭像
捨棄
作者 最佳答案

i found a solution

# Mobile Field to be unique
@api.constrains('mobile')
def _check_mobile_unique(self):
mobile_counts = self.search_count([('mobile', '=', self.mobile), ('id', '!=', self.id)])
print(mobile_counts)
if mobile_counts > 0:
raise ValidationError("Mobile number already exists!")
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
5
10月 24
32609
1
7月 23
7268
2
7月 22
11449
2
10月 21
3242
0
8月 21
2007