this is model:
class AgencyDetail(models.Model):
from_time = models.TimeField()
to_time = models.TimeField()
模板:
<label>From Time:</label>
<select name="state3" class="fromtime">
{% for x in a %}
<option value="{{x}}">{{x}}</option>
{% endfor %
</select><br/>
<label>To Time:</label>
<select name="state4" class="totime">
{% for x in a %}
<option value="{{x}}">{{x}}</option>
{% endfor %}
</select><br/><br/>
this my views:
def registration(request, *args, **kwargs):
a=['%s:%s%s' % (h, m, ap) for ap in ('am', 'pm') for h in ([12] + range(1,12)) for m in ('00', '30')]
if request.method == "POST":
print request.POST
regis_form = AgencyDetailForm(request.POST, request.FILES)
if regis_form.is_valid():
agency_data = regis_form.save(commit = False)
agency_data.from_time=request.POST['state3']
agency_data.to_time=request.POST['state4']
agency_data.save()
return HttpResponseRedirect('/car_detail/')
else:
regis_form = AgencyDetailForm()
state_data = State.objects.all()
return render(request,"registration.html", {'regis_form': regis_form,'state_data':state_data,'a':a})
我从下午12:30开始选择时间并将所选时间保存到数据库中。 但它只保存12:30:00它不包括上午/下午。我正在使用PostgreSQL。
what i do?