I have this query
sq_edit = UsulanRekomposisiData.objects.filter(file=draft, prk=OuterRef('prk'))
cols = ['edit_jan', 'edit_feb', 'edit_mar', 'edit_apr', 'edit_mei', 'edit_jun', 'edit_jul', 'edit_aug', 'edit_sep', 'edit_okt', 'edit_nov', 'edit_des']
expr = reduce(add, (F(col) for col in cols))
lrpa = monitoring. \
annotate(
edit_jan = sq_edit.values('jan'),edit_feb = sq_edit.values('feb'),edit_mar = sq_edit.values('mar'),edit_apr = sq_edit.values('apr'),
edit_mei = sq_edit.values('mei'),edit_jun = sq_edit.values('jun'),edit_jul = sq_edit.values('jul'),edit_aug = sq_edit.values('aug'),
edit_sep = sq_edit.values('sep'),edit_okt = sq_edit.values('okt'),edit_nov = sq_edit.values('nov'),edit_des = sq_edit.values('des')
).annotate(sum_edit = expr)
I want to annotate the sum of edit in each month but it always return None i guess because one of the month value is null. I want if the value is None the F return 0 or is there any other way to get the sum?
EDIT :
the result of F(col) for col in cols
will be the the value of edit_jan to edit_des,this is the example result :
using 0 if F(col) is None else F(col) for col in cols
or F(col) for col in cols if F(col) is not None
yield the same result
for data in lrpa:
print(data.prk.no_prk, data.sum_edit, data.edit_jan, data.edit_okt)
#RESULT
2019.USLS.36.002 None None 112
2019.USLS.64.001 None None 123
2019.USLU.1.002 None None None
2021.USLW.202.003 None None None
2022.USLW.291.001 None None None
2019.USLS.63.001 None None None
2019.USLU.12.002 None None None
2019.USLU.13.002 None None None
2020.USLS.148.003 None None None
2021.USLU.24.013 None None None
2021.USLW.15.006 None None None
2021.USLW.208.003 None None None
2022.USLW.152.001 None None None
2022.USLW.296.001 None None None