In Django, is there a way to create an IntegerField in my model where I enforce an upper bound (e.g. an integer field where the value can't go higher than 10)?
1 Answer
You're looking for validators, specifically the MaxValueValidator
Raises a ValidationError with a code of 'max_value' if value is greater than max_value.
from django.core.validators import MaxValueValidator
my_field = IntegerField(validators=[MaxValueValidator(10)])
2 Comments
Hassan Baig
Oh I see. Missed that one. Thanks!
Sayse
@HassanBaig - No worries, enjoy!