I have a JSONField with some financial data. I cannot store it as a float, because I need precision, so I store it as a string.
My model looks like this
class Finance(models.Model)
bill_data = JSONField(
verbose_name=_("Bill data"),
default=dict,
blank=True,
)
then I save
bill_data = dict(paid=str(some_decimal_amount))
Finance.objects.create(bill_data=bill_data)
I try to use Cast
to convert it back to Decimal, because I need to use expressions,
Finance.objects.all().annotate(paid=Cast('bill_data__paid', DecimalField()))
I get an error
return self.cursor.execute(sql, params)
django.db.utils.DataError: invalid input syntax for integer: "none"
LINE 1: ...der"."bill_data", ("myapp_finance"."bill_data")::numeric(No...
Does anyone know how to use str
from JSONField
in expressions or how to handle Decimal
in JSONField
correctly?