I have used package "django-yearmonth-widget" to have year and month selection and not complete date. Here, day is fixed i.e. 1st of every month. This implementation is working fine.
Package:
pip install django-yearmonth-widget
Problem I am facing is for field "file_upload_datetime" and describe as below
- How to display month as month name and not number
- display Option 0 as --Year-- and --Month-- or something like --Select--
- Give proper label to the field
Forms
class FileUploadForm(forms.ModelForm):
file = forms.FileField(required=True,widget=forms.ClearableFileInput(attrs={'multiple':True}), label='Select Files')
file_remote = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple':True}), required=False)
class Meta():
model = FileUpload
fields= ('file_upload_datetime','file','file_remote')
widgets = {
'file_upload_datetime': DjangoYearMonthWidget(),
'file_remote':forms.HiddenInput()
}
Models
class FileUpload(models.Model):
file = models.FileField(upload_to='files')
file_remote = models.FileField(upload_to=RetailFormsConfig.remote_folder, storage=upload_storage, blank=True)
file_upload_datetime = models.DateField()
Inside view, I access month and year as date as below
file_upload_datetime = file_upload_form.cleaned_data['file_upload_datetime']
Please refer below screenshots for reference