How can I set a DateField format in django from the model?

jartymcfly picture jartymcfly · Jun 18, 2015 · Viewed 82.8k times · Source

I am creating a django application and I have the next problem: this error is shown when I want to set a date:

ValidationError [u"'12/06/2012' value has an invalid date format. It must be in YYYY-MM-DD format."]

For this model:

class ModelA(models.Model):

    date1 = models.DateField(null=True)
    date2 = models.DateField(null=True)

How can I set the DateField format to be %m/%d/%Y.

The option "input_formats" is not recognized.

Thank you!

Answer

bruno desthuilliers picture bruno desthuilliers · Jun 18, 2015

input_formats is a forms.DateField option, not a model.DateField option. You have to set it in your form, not in your models.