Answer the question
In order to leave comments, you need to log in
Django. How to limit the minimum value of a numeric field in a model?
Hello. I need to make the model so that, when adding an ad, when the user enters the price, he can only do this in the format, for example: 10000, i.e. thousand, and not just 10, thinking that people will understand anyway, because the site search should find exactly 3-digit numbers and above, but not below.
So that you can enter only like this:
But it’s impossible, if it means that this is also 50 thousand:
Here is a field from the model:
price = models.IntegerField(default=0, max_digits=4, blank=True, verbose_name='Цена')
Answer the question
In order to leave comments, you need to log in
Use validator :
from django.core.validators import MinValueValidator
price = models.IntegerField(default=0,
max_digits=4,
blank=True,
verbose_name='Цена',
validators=[MinValueValidator(1000)])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question