Is there any way I can get django to store my data in postgresql as 'dd-mm-yyyy' (if required) and have the django forms validate for 'dd-mm-yyyy'?
(I have tried without much success things like:
DATE_INPUT_FORMATS = ('%d-%m-%Y') USE_I18N = True USE_L10N = True
And done a lot of googling but no success :(
django default date to be in format %d-%m-%Y.
The full tag to print just the current year is {% now "Y" %} . Note that the Y must be in quotes. For the record, {% now %} won't give proper results for users within different time zone than the server.
Press Control+1 or Command+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type. You can adjust this format in the last step below.
The problem turned out to be that I needed both the ISO and UK date formats in the settings.py
file like so:
DATE_INPUT_FORMATS = ('%d-%m-%Y','%Y-%m-%d')
and then the forms.py adjusted to the following:
class ClientDetailsForm(ModelForm): date_of_birth = DateField(input_formats=settings.DATE_INPUT_FORMATS) class Meta: model = ClientDetails
Why USE_L10N = True
can't just do this I don't know!
[Thanks to this and this]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With