How can I create an integer field for a model such that the minimum allowed integer is 1? I noticed Django has a PositiveIntegerField
documented here but it allows 0s.
Use validators:
from django.core.validators import MinValueValidator
class MyModel(models.Model):
num = models.PositiveIntegerField(validators=[MinValueValidator(1)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With