python - 注释功能给我一个错误的结果
问题描述
我在我的 django 应用程序中设置了以下三个模型:
class SubCategory(models.Model):
name = models.CharField('Nome della sottocategoria', max_length=30)
class Materials(models.Model):
subcategory= models.ForeignKey(SubCategory)
quantity=models.DecimalField()
price=models.DecimalField()
class Costs_materials(models.Model):
subcategory= models.ForeignKey(SubCategory)
quantity=models.DecimalField()
在我看来,我设置了以下代码:
agg=Subcategory.objects.annotate(giacenza=Coalesce(Sum('materials__quantity'), 0)).annotate(
utilizzato=Coalesce(Sum('costs_materials__quantity'), 0))
一切正常,但如果我尝试添加另一个注释功能,广告示例:
agg=Subcategory.objects.annotate(giacenza=Coalesce(Sum('materials__quantity'), 0)).annotate(
utilizzato=Coalesce(Sum('costs_materials__quantity'), 0))
giacenza 和 utilizzato 的结果都不对,但结果却是对的两倍。如果结果必须为 10,则示例为 20。
错误在哪里??
解决方案
推荐阅读
- machine-learning - 如何找到多个变量的值,以便函数返回最高值
- jquery - 按属性统计当天的全日历事件
- python - 如何将 Python DataFrame 传递给 UiPath?
- sas - 如何通过 EG 上的 API (POST) 发送 .JSON 文件?
- c++ - 显式默认的 constexpr ctor 是否应该允许非 constexpr 初始化
- python - 在这种情况下,Python pandas 数据框合并如何工作?
- python - 在 CPU 上运行 Tensorflow 时抑制 OpenMP 调试消息
- git-submodules - Gerrit 将更改提交到 git 子模块
- c#-4.0 - 正则表达式查找名字后的中间首字母
- python - Python Crash Course 游戏:子弹不发射