I have done annotation on Student objects so that it has two new fields -> project_count and member_count as follows:
top_students = Student.objects.annotate(project_count= Count('project'), member_count = Count('member_student'))
I would now like to perform sum of these two values at database level. i.e return something like:
total_count = project_count + member_count
I have tried using .extra() like this:
top_students = Student.objects.annotate(project_count= Count('project'), member_count = Count('member_student')).extra(
select = {'total_count': 'project_count + member_count'},
order_by = ('total_count', )
)
But it shows an error : OperationalError: (1054, "Unknown column 'project_count' in 'field list'")
Should I write raw SQL or is there any other way to do this: