Good afternoon, I have a view based on Form View:
class CrearPuesto(FormView):
template_name = 'crear_puesto.html'
form_class = PuestoForm
success_url = reverse_lazy('administracion:maestro_puestos')
def form_valid(self, form):
form.save()
return super(CrearPuesto, self).form_valid(form)
The form is as follows:
class PuestoForm(forms.ModelForm):
class Meta:
model = Puesto
fields =['oficina','trabajador','fecha_inicio','fecha_fin','es_jefatura']
def __init__(self, *args, **kwargs):
super(PuestoForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
self.fields[field].widget.attrs.update({
'class': 'form-control'
})
self.fields['fecha_fin'].required = False
self.fields['es_jefatura'].required = False
The problem arises when I save dates because the format that users use is d / m / y and I get a "Enter a valid date." My idea is to be able to format the date before saving it but I do not know how to do it. Thank you very much for your help.