Im trying to save the operation result in my admin.py and i have this error:
quantize result has too many digits for current context
....
def save_model(self, request, obj, form, change):
usuario_libra = obj.consignee.membresia.libra
valores = Valores.objects.get(pk=1)
vtasa = valores.tasa
vaduana = valores.aduana
vgestion = valores.gestion
vfee = valores.fee
vcombustible = valores.combustible
trans_aereo = obj.peso * usuario_libra * vtasa
aduana = (obj.peso * vaduana )*vtasa
fee_airpot = (obj.peso * vfee)*vtasa
combustible = (obj.peso * vcombustible)*vtasa
itbis = (trans_aereo+vgestion)*Decimal(0.16)
total = trans_aereo + vgestion + aduana + fee_airpot + combustible + itbis
if not obj.id:
obj.total = total
...
What this mean?, all my model fields are Decimal Any help please
Thank you
I was able to solve this problem by increasing the the 'max_digits' field option.
class Myclass(models.Model):
my_field = models.DecimalField(max_digits=11, decimal_places=2, blank=True, null=True)
Be sure to make it large enough to fit the longest number you wish to save.
If that does not work may also need to set the precision larger by:
from decimal import getcontext
...
getcontext().prec = 11
See the python decimal documentation for full context parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With