I'm facing an issue of unsupported operand type(s) for +: 'float' and 'NoneType'
actually I want to sum two different database column value in specific date range and one column has no value in this specific date range and that's why I'm facing that issue can anyone one help me
One more thing help me to solve this in simple ways because I have many more arguments like that and if I use condition to make that value to zero that will be difficult for me
the date range(modified6
, modified5
) is correct, if it contain a value, it display the number
cell = Celldetail.objects.filter(DatePur__range=[modified6, modified5]).aggregate(Sum('Cell_price'))['Cell_price__sum']
bms = BMSdetail.objects.filter(DatePur__range=[modified6, modified5]).aggregate(Sum('BMS_price'))['BMS_price__sum']
month6price : cell + bms,
the error is on bms variable because bms has no number in this date range
just use float(VarName or 0)
to convert your value to 0 if NoneTpye found, for example I use below method to solve my problem
month6price : float(cell or 0) + float(bms or 0),