這是一個初學者級別的任務。我正嘗試在django中使用以下 示例來實現日曆窗口小部件:http://djangosnippets.org/snippets/1629/
日曆按鈕表現不佳
我把這個日曆放在一個表單中,並且已經有一個提交按鈕。 我遇到的問題是我的日曆按鈕提交了我的表單,而不是顯示日曆小部件的 。日曆圖標和按鈕顯示正常,我可以從 看到它具有正確的代碼來自螢火蟲,但就是這樣。
我真正需要的是一個簡單的日曆,以及ModelForm。我不太關心如何使用JSCal2來製作任何日曆。
爲什麼我的calbutton提交表單?如何讓它顯示小部件 並正常工作?任何其他建議輕鬆獲得工作日曆?
-------------widgets.py ---------------------
calbtn = u"""<input id="calendar-inputField" /><button id="calendar-trigger"> <img src="%simages/calbutton.gif" alt="calendar" id="%s_btn"
style="cursor: pointer; height="20"; width="20"; border: 1px solid #8888aa;" title="Select date and
time"
onmouseover="this.style.background='#444444';"
onmouseout="this.style.background=''" />
</button>
<script type="text/javascript">
Calendar.setup({
trigger : "calendar-trigger",
inputField : "calendar-inputField"
inputField : "%s",
ifFormat : "%s",
button : "%s_btn",
singleClick : true,
showsTime : true
onSelect : function() { this.hide() }
});
</script>"""
class DateTimeWidget(forms.widgets.TextInput):
dformat = '%Y-%m-%d %H:%M'
def render(self, name, value, attrs=None):
# Same as the example ...
def value_from_datadict(self, data, files, name):
# Same as the example ...
class Media:
css = {
'all': ('/static/calendar/gold.css',)
}
js = ('/static/calendar/jscal2.js',
'/static/calendar/en.js',
)
- ----------- forms.py ----------------
class CustMainForm(ModelForm):
lastName = forms.CharField(max_length=20)
firstName = forms.CharField(max_length=20)
class Meta:
model = Customer
fields = ('notes', 'saleDate')
widgets = {
'notes': Textarea(attrs={'cols': 80, 'rows': 20}),
'saleDate' : DateTimeWidget(), # shown above
}