插入功能:
def done(self, request, form_list):
model_form, field_form = form_list
query = SortedDict()
for field_name in field_form.fields:
app, model, field = field_name.split('__')
name = '%s__%s' % (model, field)
value = field_form.cleaned_data[field_name]
#print value
if value or value == 0:
query[name] = value
print value
query['data_model_name'] = [model.split('__')[1] for model in field_form.model_list]
Model_name.objects.create(name=model_form.cleaned_data['report_name'],query=query)
messages.success(request, "The report has been created successfully")
return redirect('....')
我从db
获取此类输入数据输入数据:
{'Locator__creation_date':
{'start': datetime.date(2013, 11, 8), 'end': datetime.date(2013, 11, 28)}
}
如何获得此类型输出
{'Locator__creation_date':
{'start': "start": "2013-09-02", "end": "2013-10-31"}
}
我使用django框架
答案 0 :(得分:3)
要将datetime
对象强制转换为字符串,请使用datetime.strftime()
。格式字符串的语法已定义,请参阅docs。在这种情况下,你想要
myDate.strftime("%Y-%m-%d")