Good afternoon I am creating a form to create clients in Django 1.10 using forms that the framework brings. This form brings some fields that are NOT obligatory but at the time of saving it asks me to complete them. How can I solve this?
I leave the code:
forms.py
from django import forms
from apps.generales.models import Cliente
class clientesForm(forms.ModelForm):
class Meta:
model = Cliente
fields = [
'tipo_cliente',
'nombre',
'numero_documento',
'direccion',
'barrio',
'telefono',
'email',
'ciudad',
'nombre_contacto1',
'telefono_contacto1',
'nombre_contacto2',
'telefono_contacto2',
'nombre_contacto3',
'telefono_contacto3',
]
labels = {
'tipo_cliente':'Tipo de Cliente',
'nombre':'Nombre completo o razón social',
'numero_documento':'Numero de identificación',
'direccion':'Dirección',
'barrio':'Barrio',
'telefono':'Teléfono',
'email':'Em@il',
'ciudad':'Ciudad',
'nombre_contacto1':'Nombre de Contacto',
'telefono_contacto1':'Teléfono',
'nombre_contacto2':'Nombre de Contacto 2',
'telefono_contacto2':'Teléfono',
'nombre_contacto3':'Nombre de Contacto 3',
'telefono_contacto3':'Teléfono',
}
widgets = {
'tipo_cliente':forms.Select(),
'nombre':forms.TextInput(),
'numero_documento':forms.TextInput(),
'direccion':forms.TextInput(),
'barrio':forms.TextInput(),
'telefono':forms.TextInput(),
'email':forms.TextInput(),
'ciudad':forms.Select(),
'nombre_contacto1':forms.TextInput(),
'telefono_contacto1':forms.TextInput(),
'nombre_contacto2':forms.TextInput(attrs={'required': False}),
'telefono_contacto2':forms.TextInput(attrs={'required': False}),
'nombre_contacto3':forms.TextInput(attrs={'required': False}),
'telefono_contacto3':forms.TextInput(attrs={'required': False}),
}
html
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Crear</button>
</form>