def hook_get_results(self, changelist):
result_list = list(changelist.result_list)<EOL>if self.pid:<EOL><INDENT>parent = changelist.model.objects.get(pk=self.pid)<EOL>parent = changelist.model(pk=getattr(parent, self.pid_field_real, None))<EOL>setattr(parent, self.UPPER_LEVEL_MODEL_ATTR, True)<EOL>result_list = [parent] + result_list<EOL><DEDENT>kwargs_filter = {'<STR_LIT>' % self.pid_field: result_list}<EOL>stats_qs = changelist.model.objects.filter(<EOL>**kwargs_filter).values_list(self.pid_field).annotate(cnt=models.Count(self.pid_field))<EOL>stats = {item[<NUM_LIT:0>]: item[<NUM_LIT:1>] for item in stats_qs}<EOL>for item in result_list:<EOL><INDENT>if hasattr(item, self.CHILD_COUNT_MODEL_ATTR):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>setattr(item, self.CHILD_COUNT_MODEL_ATTR, stats[item.id])<EOL><DEDENT>except KeyError:<EOL><INDENT>setattr(item, self.CHILD_COUNT_MODEL_ATTR, <NUM_LIT:0>)<EOL><DEDENT><DEDENT>changelist.result_list = result_list<EOL>
Triggered by `ChangeList.get_results()`.