在使用DateTimeField
in ModelForm
s 时,它们看起来像文本字段。我怎样才能让它们在管理员中看起来像?(当我去管理员并添加一个节目时,我将这些字段视为日期字段)
# models.py
class Show(models.Model):
...
start_time = models.DateTimeField("Event Time")
sale_end_time = models.DateTimeField("Sale End Time")
class ShowForm(ModelForm):
class Meta:
model = Show
# views.py
def createshow(request):
if request.method == 'POST':
form = ShowForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/showsaved')
else:
form = ShowForm()
return render(request, 'BizCreateShow.html', {'ShowForm' : form})
在模板中:
<form class="form-horizontal well" action="" method="post">
{% csrf_token %}
{{ ShowForm }} </br>
<input type="submit" value="Submit">
</form>