django bootstrap3_datetime无法处理模型表单

时间:2014-11-28 10:06:57

标签: django twitter-bootstrap datetimepicker django-forms

我是Django的新手,我想在我的日期字段中使用日期时间选择器。 我尝试了bootstrap3_datetime,它似乎对我的表单运行良好,但它不适用于我的ModelForm!

这是我的代码

form.py

class AutistiForm(forms.Form):
     nome = forms.CharField(label='Nome Autista', max_length=50, required=False)
     data_inizio = forms.DateField(widget=DateTimePicker(options="format":"DD-MM-YY","pickTime":"False"}))
     data_fine = forms.DateField(widget=DateTimePicker(options={"format":"DD-MM-YY","pickTime":"False"}))


class ServiziForm(ModelForm):
    class Meta:
        model = Servizi
        fields = '__all__'
        widgets = {'data': DateTimePicker(options={"format":"DD-MM-YY",                                            "id":"id_data",  "pickTime":"True"}),}

autisti.htlm --->这是工作

<!DOCTYPE html>
{% load static %}
<html>
<head>
    <link href="{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="{{ STATIC_URL }}js/bootstrap.js"></script>
    {{ form.media }}
    <title></title>
</head>
<body>
<form action="" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="OK">
</form>
{% for autista in queryAutisti %}
    {{ autista.autista }}
{% endfor %}
</body>
</html>

servizi.html ---&GT;这里不起作用

<!DOCTYPE html>
{% load static %}
<html>
<head>
<link href="{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="{{ STATIC_URL }}js/bootstrap.js"></script>
    {{ form.media }}

</head>
<body>
<form action="" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="OK" class="btn-default">
</form>
</body>

</html>

感谢您的回答!!

0 个答案:

没有答案