Reputation: 15824
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)?
Upvotes: 2
Views: 308
Reputation: 43300
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)])
Upvotes: 2