D
D
Dagcrag2017-05-28 16:43:41
Django
Dagcrag, 2017-05-28 16:43:41

Django. Is it possible in django-orm to set a minimum value for a field of type FloatField in a model?

There is a table with prices in the database. Created it through the jago model. The price field is a FloatField. The model is registered with django-admin. When adding\changing values ​​through j-admin, values ​​< 0 can be specified in this table. Is it possible to put some kind of flag so that only values ​​\u003e 0.1 can be added to j-admin?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2017-05-28
@Dagcrag

from django.core import validators

price = models.FloatField(..., validators=[validators.MinValueValidator(0.1)])

https://docs.djangoproject.com/en/1.11/ref/validators/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question