FloppyForms SplitDateTimeWidget不会在表单中设置现有日期

时间:2014-08-21 07:51:25

标签: django forms django-floppyforms

我已将FloppyForms SplitDateTimeWidget添加到我的日期时间字段中,如果已经存储了值,则表单中的时间按预期正确设置,但日期只是dd/mm/yyyy

为了让表单正确设置日期值,我缺少什么?

# forms.py
from django import forms

from generic.forms.widgets.floppyforms import SplitDateTimeWidget

from consoles.models import Event


class EventForm(forms.ModelForm):

    class Meta:
        model = Event
        exclude = ('slug',)
        widgets = {
            'qualifying_date': SplitDateTimeWidget(date_format='%d/%m/%Y'),
        }

生成的HTML具有正确的值属性,但小部件只显示'dd / mm / yyyy'

<input type="date" name="start_0" value="21/08/2014" id="id_start_0">
<input type="time" name="start_1" value="10:00:00" id="id_start_1">

1 个答案:

答案 0 :(得分:0)

根据此问题django: SplitDateTimeWidget ignores date_format,您还必须指定input_date_format

class EventForm(forms.ModelForm):

  class Meta:
    model = Event
    exclude = ('slug',)
    widgets = {
        'qualifying_date': SplitDateTimeWidget(date_format='%d/%m/%Y'),
    }
    qualifying_date = SplitDateTimeField(input_date_formats=['%d/%m/%Y'],
                           input_time_formats=['%H:%M'])