def get_total_co2_electric(self, obj):
totalpieces = ElectricBike.objects.all().aggregate(total_co2_electric=Sum('co2'))
return totalpieces["total_co2_electric"]
# Total Co2 save by Electric
def get_total_co2_classic(self, obj):
totalprice = ClassicBike.objects.all().aggregate(total_co2_classic=Sum('co2'))
return totalprice["total_co2_classic"]
def get_total_co2(self):
totalprice = (self.get_total_co2_classic() + self.get_total_co2_electric())
return totalprice
我正在尝试添加这两个def标记并获得结果,但出现错误“接受1个位置参数,但给出了2个” 那么如何添加
答案 0 :(得分:0)
您删除obj并执行类似的操作
def get_total_co2_electric(self):
totalpieces = ElectricBike.objects.all().aggregate(total_co2_electric=Sum('co2'))
return totalpieces["total_co2_electric"]