1
Good afternoon Personal.
As a way of learning I am creating a system in Django with Client Registration.
Could someone help me in logic so that in the register I can choose CPF or CNPJ.
My Models are like this currently:
class Cliente(models.Model):
razao_social = models.CharField(max_length=80)
nome_fantasia = models.CharField(max_length=80)
cliente_classificacao = models.ForeignKey(ClienteClassificacao, null=False, blank=False, on_delete=models.PROTECT)
cliente_situacao = models.ForeignKey(ClienteSituacao, null=False, blank=False, on_delete=models.PROTECT)
cep = models.CharField(max_length=9)
endereco = models.CharField(max_length=100)
numero = models.CharField(max_length=6)
bairro = models.CharField(max_length=100)
municipio = models.CharField(max_length=50)
estado = models.CharField(max_length=100)
def __str__(self):
return self.nome_fantasia
and my stem is like this:
class ClienteForm(ModelForm):
cep = BRZipCodeField(max_length=9)
class Meta:
model = Cliente
fields = ['razao_social', 'nome_fantasia', 'cliente_classificacao', 'cliente_situacao',
'cep', 'endereco', 'numero', 'bairro', 'municipio', 'estado']
My intention is at the time of registration select the customer’s rating and as the rating the form already change the field mask.
Grateful
You can do this automatically with ajax, analyzing with an if where up to 11 characters are mapped with the CPF structure (XXX.XXX.XXX-XX), if it exceeds this value, limited to 14 consider the CNPJ formatting (XX.XXX.XXX/XXXX-XX). Remembering that, it is great to put the validation of the calculation to verify these numbers. CPF: https://dicasdeprogramacao.com.br/algoritmo-validar-cpf/ CNPJ: http://www.macoratti.net/alg_cnpj.htm
– Felipe Guimarães
Please correct the code. Paste the code here, as it comes from the text editor, and use the button
{}
to format.– jsbueno
Okay, thanks for the tip.
– Emilio Eiji Inaba
@Emilioeijiinaba actually Django does not do this - it has to be done via javascript in the browser, and does not have a ready Django object to generate this code
– nosklo