title: changing from SerializerMethodField() to annotate()
body: <p>I am new to django and django-rest-framework and I encounter a project where I need to optimize an API endpoint. Found that a SerializerMethodField() is causing a duplicate queries on SQL which I think is a N+1 problem. I am currently reading and trying to explore annotate() but found the logic computation to be complicated and I am stuck on how can I convert this to annotate(). Does anyone have a an idea on how to properly implement this? Please see the below code. Hope anyone can guide me as I already am stuck for several days on this. Thank you very much.</p>
  <p>serializer.py:</p>
  <pre><code>class BootcampClassStatisticsSerializer(ModelBaseSerializer):
      attendance_rating = serializers.SerializerMethodField()
  
      def get_attendance_rating(self, instance):
          attendance_rating = None
          attendance_count = 0
          present_count = 0
  
          bootcampers = instance.bootcamper_set.all()
          date = self.context.get('date')
  
          for bootcamper in bootcampers:
              attendances = bootcamper.dailyattendance_set.all()
              if date:
                  attendances = attendances.filter(date=date)
  
              present_attendances = attendances.filter(status=constants.PRESENT)
              if instance.class_type == constants.DAY:
                  attendance_count += len(attendances) * 2
                  for item in present_attendances:
                      if item.duration == 'wd':
                          present_count += 2
                      if item.duration == 'hd':
                          present_count += 1
  
              if instance.class_type == constants.NIGHT:
                  attendance_count += len(attendances)
                  present_count += len(present_attendances)
  
          if attendance_count:
              attendance_rating = round(present_count / attendance_count * 100, 2)
  
          return attendance_rating
  
      class Meta:
          model = BootcampClass
          fields = (
              'id',
              'batch_number',
              'start_date',
              'end_date',
              'class_type',
              'attendance_rating'
  </code></pre>
  <p>views.py:</p>
  <pre><code>class BootcampClassStatisticsList(APIView):
      queryset = BootcampClass.objects.all()
      serializer = BootcampClassStatisticsSerializer()
      return Response(serializer, status=status.HTTP_200_OK)
  </code></pre>