I am using this code and I get a result which is not what I expect
queryset= User.objects.annotate(earned_leave=Sum('logs__work_hours'))
Here is my data
"logs":
{
"id": 96,
"time_in": "11:43:34",
"time_out": "21:25:49",
"user": "admin",
"date_created": "2022-10-21",
"work_hours": 10,
"last_action": "logout",
"earned_credit": "0.38400"
}
and here is the result
"earned_leave": 20
Tried this solution but I'm not comfortable with it
queryset= User.objects.annotate(earned_leave=Sum('logs__work_hours')/2)
I cannot use distinct=True
since it won't count same values