1 回答

TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊
使用脆皮表格,我認(rèn)為您需要一個表格。
class ClubSessionForm(forms.ModelForm):
class Meta:
model = ClubSession
fields = ['location', 'coach', 'date', 'details']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['date'].widget.attrs.update({'type': 'datetime-local'})
class SessionCreateView(CreateView):
model = ClubSession
form_class = ClubSessionForm
template_name = 'session_new.html'
請記住,并非所有瀏覽器都支持<input type="datetime-local">——我相信只有 Chrome 和 Opera 支持。如果您需要它在所有瀏覽器中工作,您將需要一個 JS 解決方案。
添加回答
舉報