2π
β
It appears that the JS library and DateTimeInputField are correctly configured to allow the new datetime format, but the model cannot validate the new datetime format. Accordingly it will not save the data.
If this is correct, settings.py
can be modified to allow for different input formats.
Be sure that USE_L10N = False
otherwise it will override the custom formats listed below.
Add the following to the bottom of settings.py
:
from django.conf.global_settings import DATETIME_INPUT_FORMATS, DATE_INPUT_FORMATS
DATE_INPUT_FORMATS += ("%d-%m-%Y",)
DATETIME_INPUT_FORMATS += ("%d-%m-%Y %H:%M:%S",)
π€Dylan
1π
I had the same problem and i solved it by defining the field in ModelForm:
date = forms.DateTimeField(input_formats=['%d-%m-%Y %H:%M:%S']
class Meta:
model = Quotation
fields = [
'full_name',
'organisation',
'address',
'date',
'type',
'description',
'budget',
]
def __init__(self, *args, **kwargs):
super(YourModelName, self).__init__(*args, **kwargs)
self.fields['date'].widget.attrs.update({'class': 'form-control', 'id': 'm_datetimepicker_1'})
Also modify your javascript format to βdd-mm-yyyy hh:ii:ssβ
π€alex
Source:stackexchange.com