Trying to perform an operation on a Django queryset but running into issues

I am trying to write a queryset operation that transforms the first table into the second table as efficiently as possible
This is the criteria:
For each name, how many unique schools are affiliated with it? Also, the exact names and schools are unknown beforehand.

Name School
John USC
John USC
John UCLA
Adam UCSD
Adam USC
Name num_unique_schools
John 2
Adam 2

Try something like

from django.db.models import Count
YourModel.objects.values('name').annotate(num_unique_schools=Count('name'))