title: How do I return a count of linked objects in a GenericRelation field in a DRF Serializer?
body: <p>There are a number of questions about <a href="https://stackoverflow.com/questions/21310400/how-to-serialize-a-genericrelation-in-django">serializing GenericRelations</a> in Django Rest Framework however I have a use case where I want to simply return the count of objects in the GenericRelation field only and not serialize them. The documentation and existing questions I can find do not cover this.</p>
  
  <p>I thought it might be as simple as returning the <code>len(value)</code> in a custom Serializer, however that produces the following throw:</p>
  
  <pre><code>object of type 'GenericRelatedObjectManager' has no len()
  </code></pre>
  
  <p>My failed attempt:</p>
  
  <pre><code>class ObjectCountSerializer(serializers.RelatedField):
      """
      Return the count of related objects.
      """
  
      def to_representation(self, value):
          return len(value)
  
  class PostListSerializer(serializers.ModelSerializer):
      """
      Main serializers for the writings module
      """
      author = MemberListSerializer(many=False, read_only=True)
      comments = ObjectCountSerializer(read_only=True)
  
      class Meta:
          model = Post
          fields = (
              'id',
              'slug',
              'url',
              'title',
              'description',
              'created',
              'edited',
              'author',
              'comments'
          )
          lookup_field = 'slug'
          extra_kwargs = {
              'url': {'lookup_field': 'slug'}
          }
  </code></pre>
  
  <p>How do I simply return the count of objects in the relation?</p>