from django import form
from awesomite.models import tasks
class todoform(forms.ModelForm):
title = forms.CharField(max_length=250, help_text="Please enter a title")
description = forms.CharField(max_length=400, help_text="Please enter title description")
time = forms.DateTimeField()
class Meta:
model = tasks
fields = ('title','description','time')
在上面的代码中,我希望在显示表单时有一个日期选择器和时间选择器(如管理页面中所示)。我在其他参考文献中搜索了这个,发现很难实现或遵循。我是django的新手。
答案 0 :(得分:1)
尝试:
from django import form
from awesomite.models import tasks
from django.contrib.admin import widgets
class todoform(forms.ModelForm):
title = forms.CharField(max_length=250, help_text="Please enter a title")
description = forms.CharField(max_length=400, help_text="Please enter title description")
time = forms.DateTimeField(widget=widgets.AdminSplitDateTime())
class Meta:
model = tasks
fields = ('title','description','time')
您应该在表单>媒体类中或直接在模板
中包含其他媒体文件(参见 - > Using Django time/date widgets in custom form)