try:
    from collections import Counter
except ImportError:
    from backport_collections import Counter

import datetime

from parler.managers import TranslatableManager


class RelatedManager(TranslatableManager):

    def get_query_set(self):
        qs = super(RelatedManager, self).get_query_set()
        return qs.select_related('featured_image')

    def get_months(self, namespace):
        """
        Get months with posts count for given namespace string.

        This means how much posts there are in each month. Results are ordered
        by date.
        """

        # This is done in a naive way as Django is having tough time while
        # aggregating on date fields
        entries = self.filter(namespace__namespace=namespace)
        dates = entries.values_list('publishing_date', flat=True)
        dates = [(x.year, x.month) for x in dates]
        date_counter = Counter(dates)
        dates = set(dates)
        dates = sorted(dates, reverse=True)
        months = [
            # Use day=3 to make sure timezone won't affect this hacks'
            # month value. There are UTC+14 and UTC-12 timezones.
            {'date': datetime.date(year=year, month=month, day=3),
             'count': date_counter[(year, month)]}
            for year, month in dates]
        return months

@@ -99,17 +99,16 @@
 Counter%0A
-%0A
 import d
@@ -115,16 +115,91 @@
 atetime%0A
+from django.db.models import Count%0A%0Afrom aldryn_people.models import Person
 %0Afrom pa
@@ -1380,8 +1380,451 @@
  months%0A
+%0A    def get_authors(self, namespace):%0A        %22%22%22Get authors with posts count for given namespace string.%22%22%22%0A%0A        # This methods relies on the facts that:%0A        # - each Article has author assigned on save()%0A        # - Article.namespace.namespace is effectively unique for Article models%0A        return Person.objects.filter(%0A            article__namespace__namespace=namespace).annotate(%0A                num_entries=Count('article'))%0A

add get_authors() method