I have in Django class base UpdateView with form:
class MyForm(forms.ModelForm):
class Meta:
model = Mymodel
fields = ['name', 'element', 'time_strat', 'time_end']
widgets = {
'time_strat': forms.DateTimeInput(attrs={'type': 'datetime-local'}),
'time_end': forms.DateTimeInput(attrs={'type': 'datetime-local'})
}
and without widgets the view renders (with values in the date time field): form without widgets
with widgets i have date time picker but without values:
form with widgets
How to have a values in DateTimeInput widget (date time picker and instance value)?
solved, for it to work, appropriate format need to set: 2021-07-01T01:00 or 2021-01-01T01:00:00.
'time_end': forms.DateTimeInput(format=('%Y-%m-%dT%H:%M'), attrs={'type': 'datetime-local'})
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