Login

Snippets by tcarranza

Snippet List

CNPJ and CPF Validation for Models

The code was placed inside a helper file without using a class. The Django validator was not designed to work with validator classes, it would appear, so retrieving the value from the field proved to be a hassle. Just create a helper file, import it on your model, and use the validator in the standard way, as such: cnpj = models.CharField(unique=True, max_length=14, validators=[validate_CNPJ]) cpf = models.CharField(unique=True, max_length=14, validators=[validate_CPF])

  • model
  • validation
  • cnpj
  • cpf
Read More

tcarranza has posted 1 snippet.