Django - 尝试使用datetime

时间:2016-10-01 07:17:49

标签: python django

我的模型中有这个:

start_date = models.DateField(default=datetime.date, blank=True)
stop_date = models.DateField(default=datetime.date, blank=True)

在我看来,我有:

start_date = datetime.date(int(request.POST.get('start_year')),
                           convert_month_to_int(request.POST.get('start_month')),
                           int(request.POST.get('start_day')))
end_date = datetime.date(int(request.POST.get('end_year')),
                         convert_month_to_int(request.POST.get('end_month')),
                         int(request.POST.get('end_day')))

在我保存到数据库之前。

HTML就是这样:

                        <label class="col-md-4"> Start Date: </label>
                        <select class="selectpicker" data-width="auto" name="start_month" id="start_month" required>
                            {% for month in month_list %}
                                <option value="{{ month }}" {% if path_start and path_start.1 == month %} selected {% endif %}> {{ month }} </option>
                            {% endfor %}
                        </select>
                        /
                        <select class="selectpicker" data-width="auto" name="start_day" id="start_day" required>
                            {% for day in day_list %}
                                <option value="{{ day }}" {% if path_start and path_start.2 == day %} selected {% endif %}> {{ day }} </option>
                            {% endfor %}
                        </select>
                        /
                        <select class="selectpicker" data-width="auto" name="start_year" id="start_year" required>
                            {% for year in year_list %}
                                <option value="{{ year }}" {% if path_start and path_start.0 == year %} selected {% endif %}> {{ year }} </option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="row">
                        <label class="col-md-4">End Date: </label>
                        <select class="selectpicker" data-width="auto" name="end_month" id="end_month">
                            {% for month in month_list %}
                                <option value="{{ month }}" {% if path_end and path_end.1 == month %} selected {% endif %}> {{ month }} </option>
                            {% endfor %}
                        </select>
                        /
                        <select class="selectpicker" data-width="auto" name="end_day" id="end_day">
                            {% for day in day_list %}
                                <option value="{{ day }}" {% if path_end and path_end.2 == day %} selected {% endif %}> {{ day }} </option>
                            {% endfor %}
                        </select>
                        /
                        <select class="selectpicker" data-width="auto" name="end_year" id="end_year">
                            {% for year in year_list %}
                                <option value="{{ year }}" {% if path_end and path_end.0 == year %} selected {% endif %}> {{ year }} </option>
                            {% endfor %}
                        </select>

当我尝试保存时,我收到错误'必需参数'年'(pos 1)未找到'。我无法弄清楚为什么会这样。任何意见,将不胜感激。谢谢。

0 个答案:

没有答案