NegativeNumberValidator

Documentation for the `NegativeNumberValidator ` class.

Namespace blazingapi.orm.validators

The NegativeNumberValidator class is a validator that checks if a value is a negative number.

How to Use

from blazingapi.orm.models import Model
from blazingapi.orm.fields import FloatField
from blazingapi.orm.validators import NegativeNumberValidator


class Debt(Model):
    amount = FloatField(validators=[NegativeNumberValidator()])

Class Definition

class NegativeNumberValidator(BaseValidator):

    def __call__(self, value):
        if value is not None and value >= 0:
            raise ValueError(f"Value {value} must be a negative number")