0
我试图将DECIMALFIELD留空。如果它不符合标准,我希望我的“if语句”将该字段留空。我的模特已被设置为blank=True, null=True
。如果不符合标准,则将DECIMALFIELD留空
def clean_xrate(self):
xrate_date = self.cleaned_data.get(str("date"))
currency = self.cleaned_data.get("currency")
curr = currency
if not xrate_date:
raise ValidationError('Error')
elif curr == 'USD':
xrate = 'NULL' <---This doesn't work. ☹️
else:
prior_date_rate = cr.get_rate(curr, 'USD', xrate_date)
xrate = "{0:.4f}".format(prior_date_rate)
return xrate
在此先感谢您的帮助!
xrate ='None'? –