Django date input format

I am using Django 1.7 and Python 2.7 and I am using Model Forms.

I have a template that allows the date format in a specific way:

DATE_INPUT_FORMATS = (

    '%m.  %Y',  # mm.  yyyy (. and two space separator).
    '%m. %Y',  # mm. yyyy (. and one space separator).
    '%m.%Y',  # mm.yyyy (dot separator).
    '%m-%Y',  # mm-yyyy (dash separator).
    '%Y.%m',  # yyyy.mm (dot separator).
    '%Y/%m',  # yyyy/mm (forward slash separator).
    '%Y-%m',  # yyyy-mm (dash separator).
    '%m/%Y',  # mm/yyyy (forward slash separator) (default date format).

)

      

I have set up my model form to allow the date field input format:

input_formats = {
    'award_grant_date': settings.DATE_INPUT_FORMATS,
}

      

But the above code always returns an input error like "Please enter a valid date".

So I did some SO thread reading and I entered the following line of code into the init Model Form to get the date working:

self.fields['award_grant_date'].input_formats = (settings.DATE_INPUT_FORMATS)

      

So my question is: Why doesn't the model form input work, but the code at the beginning of the form model does work? This might be an easy answer, but I couldn't find the answer in the docs or SO posts.

+3


source to share





All Articles