id | started | finished
1 | 2 | 1
2 | 2 | 1
1 | 4 | 3
class Habr(models.Model):
idn = models.Integer()
started = models.Integer()
finished = models.Integer()
input: from app.models import Habr
input: habr = Habr.objects.all()
input: from django.db.models import Sum
input: habr.values('idn').annotate(s1=Sum('started'),s2=Sum('finished'))
output: [{'idn': 1, 's2': 4, 's1': 6}, {'idn': 2, 's2': 1, 's1': 2}]