İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
6620 Görünümler

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

Avatar
Vazgeç
Üretici En İyi Yanıt

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!")
Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
5
Eki 24
32639
1
Tem 23
7292
2
Tem 22
11479
2
Eki 21
3283
0
Ağu 21
2021