Reputation: 107
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
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
I get the error "This field is required", if the "date" field is left blank. Considering that I have used "blank = True", I am unable to figure out the reason for the error. I also tried searching if there are any issues with "DateField". How can I solve this problem? I am a newbie. I have posted relevant code.
Upvotes: 3
Views: 931
Reputation: 2027
Set the field to 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
Upvotes: 8