I have a DateTimeField
that users have to manually type the date and time (YYYY-MM-DD Hour:Minute am/pm) in. I want to be able to use the Django calendar input for users to select a date on that, instead of having to type it in. I believe this can be done through the DateTime
form field type, but am not certain. I would greatly appreciate any help with this issue.
forms.py
class LessonForm(forms.ModelForm):
lesson_instrument = forms.ChoiceField(choices=instrument_list, widget=forms.Select(attrs={'class' : 'form-control', 'required' : 'True'}))
lesson_level1 = forms.ChoiceField(choices=level_list, widget=forms.Select(attrs={'class' : 'form-control', 'required' : 'True'}))
lesson_level2 = forms.ChoiceField(choices=level_list, required=False, widget=forms.Select(attrs={'class' : 'form-control'}))
lesson_level3 = forms.ChoiceField(choices=level_list, required=False, widget=forms.Select(attrs={'class' : 'form-control'}))
lesson_length = forms.ChoiceField(choices=length_list, widget=forms.Select(attrs={'class' : 'form-control', 'required' : 'True'}))
lesson_datetime_start = forms.DateTimeField(input_formats=['%Y-%m-%d %I:%M %p'], widget=forms.DateTimeInput(attrs={'class': 'form-control', 'placeholder':'YYYY-MM-DD Hour:Minute am/pm'}))
lesson_datetime_end = forms.DateTimeField(input_formats=['%Y-%m-%d %I:%M %p'], required=False, widget=forms.DateTimeInput(attrs={'class': 'form-control', 'placeholder':'YYYY-MM-DD Hour:Minute am/pm'}))
lesson_weekly = forms.BooleanField(required=False)
class Meta:
model = Lesson
fields = ('lesson_instrument', 'lesson_level1', 'lesson_level2', 'lesson_level3', 'lesson_length', 'lesson_datetime_start', 'lesson_datetime_end', 'lesson_weekly')