114
PositiveIntegerField
ensures no integer less than 0 will be accepted. Your validators seem to handle the minimum and maximum values correctly. All you are missing is default
for the default value. So something like
overs = models.PositiveIntegerField(default=10, validators=[MinValueValidator(1), MaxValueValidator(100)])
0
Since the aim is to create an Integer Field with max and min values, another solution could be to create a select box with numbers from 1 through 100 instead of an input field where the value has to be validated later.
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
class Match(models.Model):
overs = models.IntegerField(default=1, choices=((i,i) for i in range(1, 101)))
- [Django]-How to configure where to redirect after a log out in Django?
- [Django]-Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events
- [Django]-Django urls without a trailing slash do not redirect
Source:stackexchange.com