title: Django Rest framework- getting total number of rows
body: <p>I would like to output a field that counts the number of Candidat in Candidat Model. I am currently using the following serializer:</p>
  
  <pre><code>class CountCSerializer(serializers.ModelSerializer):
      user_count = serializers.SerializerMethodField()
  
      class Meta:
          model = Candidat
          fields = ( 'user_count',)   
  
      def get_user_count(self, obj):
          return Candidat.objects.count()
  </code></pre>
  
  <p>and the following api:</p>
  
  <pre><code>class CountCViewSet(ModelViewSet):
      queryset = Candidat.objects.all()
      serializer_class = CountCSerializer
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>router.register(r'CountC', CountCViewSet, base_name='users-count')
  </code></pre>
  
  <p>models.py:</p>
  
  <pre><code>class Candidat(models.Model):           
      name = models.CharField(max_length=50)
      lastName = models.CharField(max_length=50)
      email = models.CharField(max_length=50)
      tel = models.CharField(max_length=50, default=0)
      password = models.CharField(max_length=50)
      civility = models.CharField(max_length=50)
      birthDate = models.DateField(auto_now=False, auto_now_add=False)
      gouvernorate = models.CharField(max_length=50)
      def __str__(self):
          return "Candidat: {}".format(self.name)
  </code></pre>
  
  <p>But im getting nothing!</p>
  
  <p><a href="https://i.stack.imgur.com/ynziJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ynziJ.png" alt="enter image description here"></a></p>
  
  <p>Any help in the matter would be much appreciated.</p>