def get_all_related_companies(self, include_self=False):
parents = self.get_all_parents()<EOL>subsidiaries = self.get_all_children()<EOL>related_companies = parents | subsidiaries<EOL>if include_self is True:<EOL><INDENT>company_qs = Company.objects.filter(id=self.id)<EOL>related_companies = related_companies | company_qs<EOL><DEDENT>related_companies_ids = [company.id for company in list(set(related_companies))]<EOL>related_companies = Company.objects.filter(id__in=related_companies_ids)<EOL>return related_companies<EOL>
Return all parents and subsidiaries of the company
Include the company if include_self = True