Closed MaximeVlnve closed 5 years ago
I can help you with that, post the code of your form.
Hi, thanks in advance, here is the simple code :
class Meta:
model = Appointment
fields = ['label', 'start', 'end']
widgets = {
'start': DateTimePickerInput().start_of('app'),
'end': DateTimePickerInput().end_of('app'),
}
These are the date formats django accepts by default:
['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y']
These are the date-time formats django accepts by default:
['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M', '%Y-%m-%d', '%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M:%S.%f', '%m/%d/%Y %H:%M', '%m/%d/%Y', '%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M:%S.%f', '%m/%d/%y %H:%M', '%m/%d/%y']
If you need a format not listed here, a widget has nothing to do unless you specify it on the from field passing a input_formats
parameter.
class YourForm(forms.ModelForm):
start = forms.DateTimeField(input_formats=["%d/%m/%Y %H:%M"], widget=DatePickerInput(format="%d/%m/%Y %H:%M").start_of('app'))
end = forms.DateTimeField(input_formats=["%d/%m/%Y %H:%M"], widget=DatePickerInput(format="%d/%m/%Y %H:%M").start_of('app'))
class Meta:
model = Appointment
fields = ['label', 'start', 'end']
Oh ok, missed that info about date-time formats accepted by default. Thanks a lot for your explanation and solution.
You didn't miss that, I never mentioned it in the docs. Thanks for bringing it up, will include it in the docs next time.
Please include this on the docs 👍 I have lost some hours searching for this solution.
May I ask what start_of('app') means in the above items?
@matthpau please follow the readme to see how to use the start_of/end_of
methods, and if you have further queries open a separate issue about that.
Documentation updated to address this issue #48.
Hi,
I am currently trying to use your datetime picker and first of all i want to thank you about this useful component.
Secondly, i am here because i am french and i want to format the datetimepicker according to my locale. For that, i add to my DateTimePickerInput a format so that i have :
DateTimePickerInput(format="%d/%m/%Y %H:%M")
Basically i just wanted to invert month and day.
Also, in that case that does not work well but when i do not use a format option such as mentionned previously, your component works well (the datetime i wanted to save in my db is saved successfully).
Thanks in advance for your time,
Maxime