如何在django视图和模型中的datefield中允许null?

时间:2015-06-25 22:18:31

标签: django python-2.7 datetime django-models django-views

我的代码是:

In model:
claimed_date = models.DateField(null=True, blank=True)

In view:
claim_date = request.POST.get('date_totclaimfee','')

显示错误:

[U"''值具有无效的日期格式。它必须是YYYY-MM-DD格式。"]

All fields in views.py:

shoes_date = request.POST.get('date_shoesfee','')
vvn_receipt = request.POST.get('bill_vvnfee','')
vvn_fees = request.POST.get(str(c)+'c_vvnfee','')
vvn_date = request.POST.get('date_vvnfee',''))

mODEL.PY:
shoes_date = models.DateField(null=True, blank=True)
vvn_receipt = models.CharField(max_length=10,null=True,blank=True)
vvn_fees = models.IntegerField(null=True,blank=True,)
vvn_date = models.DateField(null=True, blank=True)
claimed_date = models.DateField(null=True, blank=True)

1 个答案:

答案 0 :(得分:0)

尝试:

claim_date = request.POST.get('date_totclaimfee', None)