'Sum of two calculated annotation in django
.annotate(
waste=Sum("processings__chunks__waste"),
completed_waste=models.Task.get_completed_waste_annotation(),
tooling_time=Sum("processings__chunks__tooling_time"),
completed_tooling_time=models.Task.get_completed_tooling_time_annotation(),
processing_time=Sum("processings__chunks__processing_time"),
completed_processing_time=models.Task.get_completed_processing_time_annotation(),
total_time=F("tooling_time") + F("processing_time"),
completed_total_time=F("completed_tooling_time") + F("completed_processing_time"),
)
I've this annotate, the problem is in the last two fields total_time and completed_total_time, when one of the fields tooling_time, processing_time is None, I get None in both of the fields.
Solution 1:[1]
The solution at the end was to calculate that two fields in the serializer with serializers.SerializerMethodField()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stefano |
