def setup(self):
        super(GetLeafMixin, self).setup()

        qs = self.model._default_manager.all()
        if hasattr(self, 'root'):
            descendants = self.root.get_descendants()
            if isinstance(descendants, list):
                descendants = [d.pk for d in descendants]
            qs = qs.exclude(pk=self.root.pk).exclude(pk__in=descendants)
        if hasattr(self, 'branch'):
            descendants = self.branch.get_descendants()
            if isinstance(descendants, list):
                descendants = [d.pk for d in descendants]
            qs = qs.exclude(pk=self.branch.pk).exclude(pk__in=descendants)

        qs = (qs.annotate(n=Max('depth')).filter(depth=F('n'), depth__gt=1)
              if self.model in (TreebeardMPPlace, TreebeardNSPlace)
              else qs.filter(children__isnull=True, parent__isnull=False))
        try:
            self.leaf = qs[qs.count() // 2]
        except __HOLE__:
            raise SkipTest


#
# Children
#
dataset/ETHPy150Open BertrandBordage/django-tree/benchmark/base.py/GetLeafMixin.setup