我正在尝试实现一个DateTimePicker小部件。
小部件
class DateTimeWidget(forms.DateTimeInput):
class Media:
js = ('js/jquery-ui-timepicker-addon.js',)
def __init__(self, attrs=None):
if attrs is not None:
self.attrs = attrs.copy()
else:
self.attrs = {'class': 'datetimepicker'}
形式
class SessionForm(forms.ModelForm):
class Meta:
model = Event
widgets = {'start_time': DateTimeWidget(),
'end_time': DateTimeWidget()}
模板
{{ form.media }}
<form action="/event/post" method="post">{% csrf_token %}
{{ form.as_p }}
</form>
<script type="text/javascript">
$('.datetimepicker').datetimepicker({
dateFormat: 'yy-mm-dd'
});
</script>
DateTimePicker 渲染得很好,但格式是默认的%Y-%m-%d %H:%M:%S
我怎样才能删除秒(有%Y-%m-%d %H:%M)?
编辑
我试图得到
<input type="text" class="datetimepicker" value="2012-04-18 11:01" />
代替
<input type="text" class="datetimepicker" value="2012-04-18 11:01:05" />