I have a field in my model that's of type DecimalField
. Even though I have blank=True
and null=True
in the options, when my model goes through form validation and that field is blank, I get an error 'This value must be a decimal number.' Can DecimalField
s not be null? I could set a default of 0 for this field but I'd rather leave it nullable.
NOTE: This field originally was not nullable, but I changed the model via a South migration to make the field nullable. I double checked the database to confirm that the column has Not NULL? = No.
Here's the field definition from the model:
reqwest_max = models.DecimalField("Maximum $", max_digits=11, decimal_places=2, blank=True, null=True)
The ModelForm definition is:
class ReqwestDetailsForm(ModelForm):
details = forms.CharField(widget=forms.Textarea(attrs={'class':'span8'}),
label = 'What do you need help with?',
required=False)
reqwest_max = forms.CharField(label = "Will Pay Up To $",
required=False)
class Meta:
model = Reqwest
widgets = {
'tags': TextInput(attrs={'size':75}),
}
Your forms.CharField
will return an empty string, not None
(Python's NULL
). Therefore it tries to set the column to ''
(empty string), not NULL
.
You should probably use a django.forms.DecimalField
in the form. See https://docs.djangoproject.com/en/dev/ref/forms/fields/#decimalfield
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With