2
我知道这已被问了很多次,但不知怎的,没有奏效。我在Song模型中有这个模型字段。“量化结果有太多的数字为当前上下文”保存上的错误
sent_score = models.DecimalField(缺省值= 0.0,max_digits = 4,decimal_places = 2,空白=真)
我认为我更新发送得分以下方式。
song_item = Song.objects.get(id=id)
com_list = Comment.objects.filter(song_id=id)
com_count = com_list.count()
pos_comments = com_list.filter(sentiment='positive')
pos_count = pos_comments.count()
getcontext().prec = 2
sent_score = Decimal(pos_count)/Decimal(com_count)
但是它仍然给我这个错误 InvalidOperation:量化结果对当前上下文过多的数位
我也试过这样的量化方法:
sc = Decimal(pos_count)/Decimal(com_count)
Decimal(sc).quantize(Decimal('12.12'), rounding = ROUND_DOWN)
song_item.sent_score = sc
song_item.save()
,但它仍然给出同样的错误,请告诉我我在哪里出错