About Minimal and Maximal Values for Numeric Fields

You can set the minimal and maximal values for a numeric field using Django validators:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from django.db import models
from django.core.validators import (
    MinValueValidator, MaxValueValidator
)

class Process(models.Model):
    progress = models.IntegerField(
        validators = [
            MinValueValidator(0), 
            MaxValueValidator(100)
        ]
    )

Tips and Tricks Programming Architecture Django 4.2 Django 3.2 Django 2.2