2

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 1

2

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)])
Sign up to request clarification or add additional context in comments.

2 Comments

Oh I see. Missed that one. Thanks!
@HassanBaig - No worries, enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.