title: django rest framework category parent and child count
body: <p>There is my model:</p>
  
  <pre><code>class Category(models.Model):
  .....
  slug = models.SlugField(verbose_name=_('Slug'))
  description = RedactorField(verbose_name=_('Description'))
  parent = models.ForeignKey('self', null=True, blank=True,
                             default=None, verbose_name=_('Parent'))
  </code></pre>
  
  <p>The thing is I need to make a api resource, using DjangoRestFramework, and serializer should contain count of childs for each category.
  Something like this, i made with inbox DRF tools like generics.ListAPIView:</p>
  
  <pre><code>[
  {
      "id": 1,
      "created": "01-08-2017 10:42 UTC",
      "modified": "01-08-2017 10:55 UTC",
      "name": "Category_1",
      "slug": "",
      "description": "",
      "parent": null,
      "child_count": 12,
  
  },
  {
      "id": 2,
      "created": "01-08-2017 10:42 UTC",
      "modified": "01-08-2017 10:55 UTC",
      "name": "SubCategory_1_1",
      "slug": "",
      "description": "",
      "parent": 1,
      "child_count": 0,
  },
  ...
  ]
  </code></pre>
  
  <p>so the queryset</p>
  
  <pre><code>Category.objects.annotate(child_count=models.Count('parent'))
  </code></pre>
  
  <p>gonna show only the count of parents (and its always equals to 1 or 0).</p>
  
  <p>There is MPTTModel lib, that possibly could solve this, but i can't use it, because of some project specific issues exists.</p>