コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6639 ビュー

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
32776
1
7月 23
7434
2
7月 22
11591
2
10月 21
3384
0
8月 21
2116