In a django form, I have the error invalid literal for int() with base 10: ” for a field I don’t fill. It occurs at the line:
if form.is_valid():
What I don’t understand is that the field has required=False. So if the field is empty, Django should not try to validate it, no?
Here is the model:
prelexDosId = models.IntegerField(max_length=7, unique=True, blank=True, null=True, default=None)
Here the form:
prelexDosId = forms.RegexField(regex=r'^[1-9]([0-9]?){6}$', required=False)
Thank you in advance,
Romain
RegexFieldis completely the wrong field to use here. I don’t understand why you need to override the default form field anyway, but if you do, you should at least useforms.IntegerField, which takes care of correctly casting the result to an integer on clean.