Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active November 8, 2020 01:44
Show Gist options
  • Save walison17/39dac4418904359e5405b557a5596a7a to your computer and use it in GitHub Desktop.
Save walison17/39dac4418904359e5405b557a5596a7a to your computer and use it in GitHub Desktop.
class UniqueDocumentValidator:
def __init__(self, message='Já existe um cadastro com esse documento, verifique e tente novamente'):
self.message = message
def __call__(self, value):
if User.objects.filter(doc=value).exists():
raise ValidationError(self.message, code='unique_document', params={'value': value})
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment