Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
6630 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
5
říj 24
32677
1
čvc 23
7320
2
čvc 22
11512
2
říj 21
3298
0
srp 21
2038