I am attempting to leave a DECIMALFIELD blank. I would like my "if statement" to leave the field blank if it doesn't meet the criteria. My model is already set to blank=True, null=True.
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
Thanks in advance for your help!
None in python will make NULL in database(most dbs). So you can do
xrate = None