Python 3.x 使用django yearmonth小部件设置年和月的默认值
如何使用django yearmonth小部件将年份设置为当前年份,将月份设置为月份\u name-1 形式 模型Python 3.x 使用django yearmonth小部件设置年和月的默认值,python-3.x,django,django-views,django-forms,Python 3.x,Django,Django Views,Django Forms,如何使用django yearmonth小部件将年份设置为当前年份,将月份设置为月份\u name-1 形式 模型 class FileUpload(models.Model): file = models.FileField(upload_to='files') file_remote = models.FileField(upload_to=RetailFormsConfig.remote_folder, storage=upload_storage, blank=True)
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()
我通过查找类来使用javascript设置默认值
current_date = new Date();
$("select.django-yearmonth-widget-year-selector")
.val(current_date.getFullYear())
.change();
$("select.django-yearmonth-widget-month-selector")
.val(current_date.getMonth()) //month starting from 0
.change();
您尝试过什么吗?是的,我尝试过使用设置默认值,但DjangoYearMonthWidget()似乎不接受默认属性。
current_date = new Date();
$("select.django-yearmonth-widget-year-selector")
.val(current_date.getFullYear())
.change();
$("select.django-yearmonth-widget-month-selector")
.val(current_date.getMonth()) //month starting from 0
.change();