Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6612 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
5
oct 24
32611
1
jul 23
7272
2
jul 22
11453
2
oct 21
3245
0
ago 21
2010