radiac/django-tagulous

Document `descendant_count` and `family_count` properties of TagTreeModel

jeffbowen opened this issue · 0 comments

Was about to build this myself before I realized that these properties already existed.

def _get_descendant_count(self):
"The sum of the counts of all descendants"
return self.get_descendants().aggregate(models.Sum("count"))["count__sum"] or 0
descendant_count = property(
_get_descendant_count, doc=_get_descendant_count.__doc__
)
def _get_family_count(self):
"The count of self plus all its descendants"
return self.descendant_count + self.count
family_count = property(_get_family_count, doc=_get_family_count.__doc__)