gpt4 book ai didi

Django 错误 : []

转载 作者:行者123 更新时间:2023-12-03 14:33:03 35 4
gpt4 key购买 nike

我在我的项目中做了以下信号:

@receiver(pre_save, sender=group1)
@disable_for_loaddata
def total_closing_group1(sender,instance,*args,**kwargs):
total_group_closing_deb_po = instance.master_group.filter(ledgergroups__Closing_balance__gte=0,balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
total_group_closing_deb_neg = instance.master_group.filter(ledgergroups__Closing_balance__lt=0,balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
total_group_closing_po_cre = instance.master_group.filter(ledgergroups__Closing_balance__gte=0,balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
total_group_closing_neg_cre = instance.master_group.filter(ledgergroups__Closing_balance__lt=0,balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
total_closing_deb_po = instance.ledgergroups.filter(Closing_balance__gte=0,group1_Name__balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
total_closing_deb_ne = instance.ledgergroups.filter(Closing_balance__lt=0,group1_Name__balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
total_closing_cre_po = instance.ledgergroups.filter(Closing_balance__gte=0,group1_Name__balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
total_closing_cre_ne = instance.ledgergroups.filter(Closing_balance__lt=0,group1_Name__balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
if total_group_closing_deb_po != None and total_group_closing_neg_cre != None and total_closing_deb_po != None and total_closing_cre_ne != None:
instance.positive_closing = total_group_closing_deb_po + abs(total_group_closing_neg_cre) + total_closing_deb_po + abs(total_closing_cre_ne)
if total_group_closing_po_cre != None and total_group_closing_deb_neg != None and total_closing_cre_po != None and total_closing_deb_ne != None:
instance.negative_closing = total_group_closing_po_cre + abs(total_group_closing_deb_neg) + total_closing_cre_po + abs(total_closing_deb_ne)

我的模型是:
class Group1(models.Model):   
group_name = models.CharField(max_length=32)
master = models.ForeignKey("self",on_delete=models.CASCADE,related_name='master_group',null=True)
negative_closing = models.DecimalField(max_digits=10,default=0,decimal_places=2,null=True)
positive_closing = models.DecimalField(max_digits=10,default=0,decimal_places=2,null=True)


class Ledger1(models.Model):
name = models.CharField(max_length=32)
group1_name = models.ForeignKey(Group1,on_delete=models.CASCADE,null=True,related_name='ledgergroups')
closing_balance = models.DecimalField(default=0.00,max_digits=10,decimal_places=2,blank=True)

一开始它工作正常,但是当我通过将数据放入字段来增加数据库的负载时突然之间。

它向我抛出错误 [<class 'decimal.InvalidOperation'>] .

这个错误意味着什么?

任何想法任何人

谢谢

最佳答案

我最近自己也遇到了这个问题。我认为我知道十进制字段的方式在我的情况下是错误的。
我认为 max_digits=x 给出整数部分的 x 值,decimal_places=y 给出小数部分的 y 值,但我错了。
max_digits 定义总数。总位数和小数位数是 max_digits 的一部分。
例如。如果 max_digits=13decimal_places=3那么该字段将存储多达 10 亿的数值,带有 3 个精确的小数。
这可能会帮助那些像我过去几个小时一样陷入困境的人。

关于Django 错误 : [<class 'decimal.InvalidOperation' >],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56458774/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com