I have a legacy database I created a model for it. It looks something like below.
class Account(models.Model):
balance = models.DecimalField(max_digits=42, decimal_places=1, default=Decimal('0.0'))
When I run the below query I get the balance field
as None
insted of using the default
value on the field.
Account.objects.get(pk=1).balance #returns None instead of Decimal(0.0).
I would like to get the default Decimal(0.0)
when legacy balance on SQL database is NULL
.
Is there a way to tell django orm to give me the default Decimal(0.0)
instead of None
.
Thanks in advance.
EDIT:
I know we can add custom methods or @property
and make it a method that returns the balance or the default value but I Also run some other queries like one's below.
Account.objects.values_list('balance') #returns [(1,),(None,),(None,)]
Which does not use the default value.