I
I
IvanOne2015-11-06 12:01:27
Django
IvanOne, 2015-11-06 12:01:27

How to resolve error with DecimalField?

Hello everyone, there is django 1.7 there is postgre. There is this field:

balance_rur = models.DecimalField(u"Баланс рубли", max_digits=15, decimal_places=2, default=0)

There is a method that works with it
if currency == RUR:
            self.balance_rur = models.F('balance_rur') + amount
elif currency == USD:
            self.balance_usd = models.F('balance_usd') + amount
self.save(update_fields=['balance_rur', "balance_usd"])

The following happens if the field contains the number 45.55 and if I add 1.35 through this method, then I get 46.9 and I get an error on this line
self.save(update_fields=['balance_rur', "balance_usd"])

Data truncated for column 'balance_rur' at row 1
How can I solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question