Vab*_*bbs 3 django validation django-forms datefield
I have following models.py code:
class try(models.Model)
date = models.CharField(max_length=10, blank=True, null=True) # statement no. 1
#also tried this instead of statement no.1 :
#date = models.DateField(blank=True, null=True)
#other statements
Run Code Online (Sandbox Code Playgroud)
Corresponding ModelForm code is:
class MyForm(ModelForm):
filing_date = DateField(input_formats=['%d-%m-%Y'], widget=DateInput(format=('%d-%m-%Y'), attrs={'class':'input-block-level datePickBootstrap', 'placeholder':'Filing date'}))
class Meta:
model = try
Run Code Online (Sandbox Code Playgroud)
如果"日期"字段留空,则会收到错误"此字段为必填项".考虑到我使用了"blank = True",我无法找出错误的原因.我也试过搜索"DateField"是否有任何问题.我怎么解决这个问题?我是新手.我已经发布了相关代码.
将字段设置为 required=False
class MyForm(ModelForm):
filing_date = DateField(input_formats=['%d-%m-%Y'],
widget=DateInput(format=('%d-%m-%Y'), attrs={'class':'input-block-level datePickBootstrap', 'placeholder':'Filing date'}),
required=False)
class Meta:
model = try
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
758 次 |
最近记录: |