I need to put a mask on entering the CPF, DDD and phone number. I'm a beginner in Python and Django and would like to know how I can display this mask at the time of typing:
For the CPF: 999.999.999-99.
For the Telephone: (99) 99999-9999.
I just created the models.py and admin.py files and as magic I already have functional forms, but I want to improve the presentation by putting the mask.
What do I have to do?
Where do I have to put this instruction?
I need some examples if I can.
models.py
class Cliente(models.Model):
SEXO_CHOICES = (
('M', u'Masculino'),
('F', u'Feminino'),
)
ESTADO_CIVIL_CHOICES = (
('S', u'Solteiro'),
('C', u'Casado'),
('D', u'Divorciado'),
('V', u'Viúvo'),
)
nome = models.CharField(max_length=60)
cpf = models.CharField(max_length=11, blank=True, null=True)
dtNascimento = models.DateField(blank=True, null=True, verbose_name='Data de nascimento')
sexo = models.CharField(max_length=1, choices=SEXO_CHOICES)
estado_civil = models.CharField(max_length=1, choices=ESTADO_CIVIL_CHOICES, verbose_name='Estado civil')
nrTelCelular = models.CharField(max_length=11, blank=True, null=True, verbose_name='Nº telefone celular')
nrTelFixo = models.CharField(max_length=11, blank=True, null=True, verbose_name='Nº telefone fixo')
def __str__(self):
return self.nome
admin.py
class ClienteAdmin(admin.ModelAdmin):
model = Cliente
list_display = ['nome','cpf', 'dtNascimento', 'sexo',
'estado_civil', 'nrTelCelular', 'nrTelFixo']
list_filter = ['sexo', 'estado_civil']
search_fields = ['nome']
admin.site.register(Cliente, ClienteAdmin)