2
I need to put a mask on the number, ID number and phone number. I am a beginner in Python and Django and would like to know how I can present this mask at the time of typing:
For CPF: 999.999.999-99.
For telephone: (99) 99999-9999.
I created only 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 I have to do?
Where do I put this instruction?
I need an example if possible.
py.models
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)
What version of
python
anddjango
is using ?– NoobSaibot
Python 3 with Django 1.11.4
– Antonio Marcos Krug Slendak
Django Input Mask Maybe I can make it work, but I think it’s obsulent.
– NoobSaibot
More recommend the use jQuery Mask Plugin
– NoobSaibot
@Wéllingthonm.Souza, Django-input-maks is not obsolete, the last commit was made on 02/07/17.
– Sidon
I didn’t even notice,.
– NoobSaibot
Unfortunately it is incompatible with Django 2.0
– Kaio Freitas