Reputation: 719
I want to limit the length of my integer field, but I don't want to use something like:
validators=[MaxValueValidator(999999999)]
What can I use instead of that?
Upvotes: 3
Views: 1947
Reputation: 59444
You can write your own validator, for example:
from django.core.validators import MaxValueValidator
class MaxLengthIntegerValidator(MaxValueValidator):
def __init__(self, length):
max_value = 10**length-1
super(MaxLengthIntegerValidator, self).__init__(max_value)
Upvotes: 3