0
votes

I am trying to update a model using a model form widget. All fields except forms.DateField is available to edit in their respective fields in the HTML form. The forms.DateField is using widget=forms.TextInput(attrs={'type': 'date'}).

publish = forms.DateField(widget=forms.TextInput(attrs={'type': 'date'}))

Screenshot of whole form is here, enter image description here

The html form output display is here. enter image description here

It is working without using a widget in another model form, giving the previously saved date time value, filled text input for edit, the field is defined below.

birth_date = forms.DateField(label='Change date of birth', help_text='(Enter date of birth in "yyyy-mm-dd" format, like 1980-12-31)')

Screenshot of output is attached, enter image description here

What should i do to display the HTML form with previously saved datetime value from the model to the input field for edit/update using widget. With widget i get a calendar. All other form input fields getting data for update, only this particular field is not showing previously saved data. I hope my question make sense. Any solution will be appreciated. Thanks in advance.

Regards, Vivek PV

1

1 Answers

0
votes

It worked finally.

I already had installed "django-bootstrap-datepicker-plus" using

pip install django-bootstrap-datepicker-plus

I changed the form field like below and worked the way how i wanted,

publish = forms.DateField(widget=forms.widgets.DateInput(attrs={'type': 'date'}))

Regards, Vivek