我在views.py 中使用以下代码
def when(request):
log.debug("test....")
reportform = ReportForm()
if request.method == 'POST':
if reportform.is_valid():
log.debug("test:%s",reportform)
reportform = reportform.save()
return render_to_response('incident/when.html',{'newreport_menu': True,
'form': reportform },context_instance=RequestContext(request))
我的模板是
{{ form.manual_date_time }}
<p id=ir-nextbutn><a href="{% url incident.views.media %}">
<form action="/member/media/" method="POST"> {% csrf_token %}
{% include "buttons/next.html" %}
</form>
模型.py
class Report(models.Model):
user = models.ForeignKey(User, null=False)
incident_number = models.CharField('Incident Number', max_length=100)
device_id = models.CharField('Device Id', max_length=100)
app_uuid = models.CharField('Unique App Id', max_length=100)
created_date_time = models.DateTimeField('Created')
manual_date_time = models.DateTimeField('Another time', null=True, blank=True)
sent_date_time = models.DateTimeField('Sent')
incident_description = models.TextField('Incident description', null=True, blank=True)
在这里,我将日期时间字段保存在数据库中。如果用户单击下一步按钮保存并转到下一页,则在字段中输入时间和日期后。但它不存储数据。我使用的是 MySql db。