我想使用我自己定制的验证器。问题是,Django看不到验证器。你知道吗
你知道吗型号.py地址:
class Market(models.Model):
money = models.DecimalField(max_digits = 15, decimal_places=2, validators=[moneyValidator])
D = decimal.Decimal
def moneyValidator(x):
if not convStr(x):
raise ValidationError
if (x <= 0) or (x >= PAYOFF) or (D(str(x))%D('0.01') != 0):
raise ValidationError
def convStr(x):
try:
str(x)
return True
except ValueError:
return False
错误消息:
NameError: name 'moneyValidator' is not defined
我想是Django从任何地方调用这个函数,不知道在哪里可以找到这个函数。我能怎么办?你知道吗
方法
moneyValidator
应该在类声明之前声明:相关问题 更多 >
编程相关推荐