Luke
Luke

Reputation: 1844

Django - ValidationError on saving a model instance containing DateField

I'm still on this view. Now I have a ValidationError while trying to save the model instance. The error is:

Enter a valid date in YYYY-MM-DD format

The DateField is correctly filled, the type of instance passed to model is unicode. I have to do something like a cast from unicode to datetime or there's something I'm doing wrong before...?

This is the traceback.

Any idea?

Thanx

Upvotes: 0

Views: 183

Answers (1)

César
César

Reputation: 10119

If you already know that the form is valid through form.is_valid(), consider working with cleaned_data instead of working directly with the request.POST:

if form.is_valid():
    ...
    fattura.data = form.cleaned_data["data"]
    fattura.diate = Decimal(form.cleaned_data["diate"])
    ...

Upvotes: 1

Related Questions