I am writing a model in django. I want to set a maximum number for a positiveintegerfield. How can I do that?
Asked
Active
Viewed 60 times
-3
-
2Possible duplicate of [How to limit the maximum value of a numeric field in a Django model?](https://stackoverflow.com/q/849142/1165509) – marcanuy Jul 22 '19 at 16:16
1 Answers
0
This should do it:
models.PositiveIntegerField(min_value=0, validators=[MaxValueValidator(100),])
More info in the Django docs: https://docs.djangoproject.com/en/2.2/ref/validators/#maxvaluevalidator

Hagyn
- 922
- 7
- 14