title: Combine prefetch_related and annotate in Django
body: <p>I have three models</p>
  <pre><code>class ModelA(models.Model):
      name = CharField(max_length=100)
  
  class ModelB(models.Model):
      modela = ForeignKey(ModelA)
  
  class ModelC(models.Model):
      modelb = ForeignKey(ModelB)
      amount = IntegerField()
  </code></pre>
  <p>I can get the output</p>
  <pre><code>name, number of model c objects
  ==============
  Some name, 312
  Another name, 17
  </code></pre>
  <p>With the queryset</p>
  <pre><code>ModelA.objects.all().prefetch_related('modelb_set', 'groupb_set__modelc_set')
  </code></pre>
  <p>and template</p>
  <pre><code>{% for modela in modela_list %}
      {% for modelb in modela.modelb_set.all %}
          {{ modelb }}, {{ modelb.modelc_set.count }}
      {% endfor %}
  {% endfor %}
  </code></pre>
  <p>Instead of counting the number of ModelC objects connected to each ModelB object I want to sum the amount field in ModelC.</p>
  <p>I don't know how to combine <code>prefetch_related</code> and <code>annotate</code> in my queryset, but it must be something like</p>
  <pre><code>(ModelA.objects.all()
         .prefetch_related('modelb_set', 'groupb_set__modelc_set')
         .annotate(total_amount=Sum('modelc_set__amount')))
  </code></pre>