Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用django yearmonth小部件设置年和月的默认值_Python 3.x_Django_Django Views_Django Forms - Fatal编程技术网

Python 3.x 使用django yearmonth小部件设置年和月的默认值

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)

如何使用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)
    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();