I want to define a database field in models.py
that accepts only 6 digits in Django.
This is how I define the field in models.py
but it can accept any positive integer;
six_digit_code = models.PositiveIntegerField(blank=False)
I am using Django v4.
CodePudding user response:
You should use validators for it
six_digit_code = models.PositiveIntegerField(validators=[MinValueValidator(100000), MaxValueValidator(999999)])