def dehydrate(self, bundle, **kwargs): result = [] id_ = bundle.obj.id for q, dir_name, other in ( (Q(parent_id=id_), 'OUTGOING', 'child'), (Q(child_id=id_), 'INCOMING', 'parent'), ): for relation in CIRelation.objects.filter(q).select_related(other): other_ci = getattr(relation, other) result.append({ 'type': CI_RELATION_TYPES.name_from_id(relation.type), 'dir': dir_name, 'id': other_ci.id, 'resource_uri': CIResourceV010( api_name=self.api_name).get_resource_uri(other_ci), 'name': other_ci.name, 'ci_type': other_ci.type_id, }) return result
def dehydrate(self, bundle, **kwargs): result = [] id_ = bundle.obj.id for q, dir_name, other in ((Q(parent_id=id_), "OUTGOING", "child"), (Q(child_id=id_), "INCOMING", "parent")): for relation in CIRelation.objects.filter(q).select_related(other): other_ci = getattr(relation, other) result.append( { "type": CI_RELATION_TYPES.name_from_id(relation.type), "dir": dir_name, "id": other_ci.id, "resource_uri": CIResourceV010(api_name=self.api_name).get_resource_uri(other_ci), "name": other_ci.name, "ci_type": other_ci.type_id, } ) return result
def dehydrate(self, bundle, **kwargs): result = [] id_ = bundle.obj.id for q, dir_name, other in ( (Q(parent_id=id_), 'OUTGOING', 'child'), (Q(child_id=id_), 'INCOMING', 'parent'), ): for relation in CIRelation.objects.filter(q).select_related(other): other_ci = getattr(relation, other) result.append( { 'type': CI_RELATION_TYPES.name_from_id(relation.type), 'dir': dir_name, 'id': other_ci.id, 'resource_uri': CIResourceV010( api_name=self.api_name ).get_resource_uri(other_ci), 'name': other_ci.name, 'ci_type': other_ci.type_id, } ) return result