I want to implement custom validation for negative value , can any one help me for this.
So in the object we do not allow user to add negative value.
CodePudding user response:
Try using the class PositiveIntegerField
.
So in your models.py something like
value = models.PositiveIntegerField(default=0)
CodePudding user response:
is this what you want:
def check(n):
if n >= 0:
# the value is positive
print("the value is positive")
else:
# the value is negative
print("the value is negative")
check(10) # i get: the value is positive
check(-10)# i get: the value is negative