I would like to modify some of the fields in my form to be validated but I do not know how. I know there are several methods but I do not understand them, if you can help me, thank you.
This is my forms.py :
from django import forms
from django.contrib.admin import widgets
from datos.models import Empleados
from django.forms import ModelForm, TextInput, Select, EmailInput
class EmpleadoForm(ModelForm):
class Meta:
model = Empleados
fields = [
'nombre',
'apellidos',
'genero',
'ci',
'cargo',
'email',
'telefono',
'documento',
'direccion',
'estado_civil',
'grado_instruccion',
'numero_de_hijos',
]
widgets = {
'nombre': TextInput(attrs={'class':'form-control','placeholder':'Introduzca nombre'}),
'apellidos': TextInput(attrs={'class':'form-control','placeholder':'Introduzca apellidos'}),
'genero': Select(attrs={'class':'form-control','placeholder':'Seleccione su género'}),
'ci': TextInput(
attrs={
'class':'form-control',
'placeholder':'Introduzca ci',
'minlength':'7',
'maxlength':'8',}),
'cargo': TextInput(attrs={'class':'form-control','placeholder':'Introduzca cargo'}),
'email': EmailInput(attrs={'class':'form-control','placeholder':'Introduzca email'}),
'telefono': TextInput(attrs={'class':'form-control','placeholder':'Introduzca solo numero de telefono'}),
'direccion': TextInput(attrs={'class':'form-control','placeholder':'Introduzca su direccion'}),
'estado_civil': Select(attrs={'class':'form-control','placeholder':'Estado civil'}),
'grado_instruccion': Select(attrs={'class':'form-control','placeholder':'Grado de instruccion'}),
'numero_de_hijos': TextInput(attrs={'class':'form-control','type':'number','placeholder':'Numero de hijos'}),
}
The fields that I want to validate are the CI: (DNI) that only accepts numeric data, the email field so that it does not accept any mail only the valid ones, name and surnames that only accept letters, and any other that I suggest and I really apologize is that I do not understand much yet.