Model-wide validation for a Field type in Django ie., validate that all DecimalField of a model is greater than 0

I have three Decimal fields that all have the same validator:

`

class MyModel(models.Model):
    one = models.DecimalField(validators=[great_than_zero])
    two = models.DecimalField(validators=[great_than_zero]
    three = models.DecimalField(validators=[great_than_zero]

`

Is there a pythonic way to enforce this validator for the entire model, so that no Decimal Field can have a negative number. If I know that all of my Decimal fields will be positive, it would be nice to not right the same piece of code for each one.



from Recent Questions - Stack Overflow https://ift.tt/3jmX7cv
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation