I've created a custom validator which checks, if the upper number in RangeField
is lower than some number.
The problem is that I can see in debug mode that the Validator.compare
returns False
but Django
raises DataError
Value "21474834555" is out of range for type integer LINE 1: ...NULL, "cena" = NULL, "poznamka" = '', "rozloha" = '[ -214748...
I can't figure out why it raises this error when it should raise ValidationError
before this.
I know that the number is out of range, that's why I've created the Validator
.
VIEW
class DopytUpdateView(LoginRequiredMaklerAccessMixin, UpdateView):
model = Dopyt
form_class = DopytForm
template_name = 'dopyty/dopyt.html'
FORM
class DopytForm(forms.ModelForm):
class Meta:
model = Dopyt
fields = [...'rozloha',...]
VALIDATOR
class RangeCompleteMaxValueValidator(MaxValueValidator):
def compare(self, a, b):
upper_ok = (a.upper > b) if a.upper else True
lower_ok = (a.lower > b) if a.lower else True
return upper_ok and lower_ok
MODEL
class Dopyt(TimeStampedModel):
...
rozloha = IntegerRangeField(null=True, blank=True, verbose_name='Rozloha [m2]',
validators=[RangeCompleteMinValueValidator(-2147483648),
RangeCompleteMaxValueValidator(2147483647)])
Do you know why it behaves this way?
EDIT
As you can see, validator returns False