title: How to get values from ForeignKey's related model in Django queryset?
body: <p>I'm having trouble accessing a field in a related model using a foreign key.</p>
  
  <p>I have two models, Person and Party as outlined below:</p>
  
  <pre><code>class Person(models.Model):
      title = models.CharField(max_length = 4, blank=True, null=True)
      first = models.CharField(max_length = 30, blank=True, null=True)
      last = models.CharField(max_length = 30, blank=True, null=True)
      party = models.ForeignKey(Party, related_name = 'parties', on_delete=models.CASCADE, blank=True, null=True)
  
      def __str__(self):
          return self.id
  
  
  class Party(models.Model):
  
      party_name = models.CharField(max_length = 50)
      party_code = models.CharField(max_length = 5)
  
      def __str__(self):
          return self.party_name
  </code></pre>
  
  <p>I'm trying to get a count of people in each party.  I'd like the result to look like:</p>
  
  <pre><code>[{
      "party_name": "Democrat",
      "total_members": 93
  },
  {
      "party_name": "Republican",
      "total_members": 32
  },
  {
      "party_name": "Non-Partisan",
      "total_members": 34
  }]
  </code></pre>
  
  <p>My serializer is as follows:</p>
  
  <pre><code>class CountPartiesSerializer(serializers.ModelSerializer):
  
      total_members = serializers.IntegerField()
  
      class Meta:
          model = Person
          fields = ('id', 'party', 'total_members')
  </code></pre>
  
  <p>And my viewset is as follows:</p>
  
  <pre><code>class CountPartiesViewSet(DefaultsMixin, viewsets.ModelViewSet):
      queryset = Person.objects.values('party__party_name').annotate(total_members = Count('id'))
      serializer_class = CountPartiesSerializer
  </code></pre>
  
  <p>But this results in the following:</p>
  
  <pre><code>[{
      "party": null,
      "total_members": 34
  },
  {
      "party": null,
      "total_members": 93
  },
  {
      "party": null,
      "total_members": 32
  }]
  </code></pre>
  
  <p>I've tried a million different things and I know I'm missing something, but I can't figure out how to get this working.  Any advice would be much appreciated!</p>